class django_table_sort.table.TableSort(request: HttpRequest, object_list: QuerySet | list, fields: list = ['__all__'], exclude: list = None, column_names: None | dict[str, str] = None, field_order: None | list[str] = None, sort_key_name: str = 'o', table_css_clases: str = 'table', table_id: str = None, template_name: str = 'django_table_sort/table.html', **kwargs)

Class to generate the table with the sort.

  • request – current HttpRequest to get the url lookups to create the links.

  • object_listQuerySet or list to fill the table.

  • fieldslist This field sets which fields should be displayed, the default value is [“__all__”] that will display all the fields in the model and the verbose_name of them as the header of the columns. You can use the column_names param to customize the headers.

  • excludelist Similar to the fields param, defines which fields should be excluded, all the field that aren’t in the exclude list will be displayed.

  • column_namesdict containing the pair {field_name: field_header}, this field has two uses, if you provide a list of X items this field will set which field will be displayed and the proper headers, if you provide a Queryset instead this field will define how the columns header will be displayed.

  • field_orderlist containing the fields in the order that you want

  • sort_key_namestr for the key name that will be used to create the sort lookup in the urls.

  • table_css_clases – class to be applied to the table.

  • table_idstr for the id of the generated tabled.

  • template_namestr template to render the table.

  • kwargs – See below

Keyword Arguments:
  • show_primary_key (bool) – Set if the

    primary key of the model should be displayed, default=``False``.

  • added_columns (list) – Extra columns to show in the table,

    should be a list object having the pair ((field_identifier, field_header), callable_function). Note that field_identifier is to mark a difference to the models fields and callable_function needs to be a function that will receive an object and return an str to print in the table column.

  • column_headers_css_classes – CSS classes to be applied to the

column headers. Should be a dictionary having the fields as keys and the css classes to be applied as values.

contains_field(lookups: list, field: str) int

Check if the field is in the sort lookups.

get_sort_url(field: str) tuple[str, str, bool, bool]

Generate the urls to sort the table for the given field.

get_table_body() str

Generate the body of the table.

get_table_headers() str

Generate the column with the link to sort.

render() str

Generate the table with the sort.

sort_columns(field_order: list)

Sort the columns according to the field order.