Skip to content

Pass the request object in the get_table_kwargs of the SingleTableMixin #966

@KommuSoft

Description

@KommuSoft

The get_table_kwargs() method allows to pass parameters when constructing a table instance:

def get_table_kwargs(self):
"""
Return the keyword arguments for instantiating the table.
Allows passing customized arguments to the table constructor, for example,
to remove the buttons column, you could define this method in your View::
def get_table_kwargs(self):
return {
'exclude': ('buttons', )
}
"""
return {}

and a Table can work with a request parameter:

def __init__(
self,
data=None,
order_by=None,
orderable=None,
empty_text=None,
exclude=None,
attrs=None,
row_attrs=None,
pinned_row_attrs=None,
sequence=None,
prefix=None,
order_by_field=None,
page_field=None,
per_page_field=None,
template_name=None,
default=None,
request=None,
show_header=None,
show_footer=True,
extra_columns=None,
):

It thus looks straightforward to pass the request, by default, to the Table such that the table can implement logic based on that request.

While the RequestConfig also injects the request object into the Table, that means it is not available at the time the __init__ function is called on the table, and people might try to generate a table without the RequestConfig.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions