Tables
TableSort
- 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.
- Parameters:
request – current
HttpRequest
to get the url lookups to create the links.object_list –
QuerySet
orlist
to fill the table.fields –
list
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.exclude –
list
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_names –
dict
containing the pair {field_name: field_header}, this field has two uses, if you provide alist
of X items this field will set which field will be displayed and the proper headers, if you provide aQueryset
instead this field will define how the columns header will be displayed.field_order –
list
containing the fields in the order that you wantsort_key_name –
str
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_id –
str
for the id of the generated tabled.template_name –
str
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``.
- show_primary_key (
- 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.
- added_columns (
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.