Skip to content

Commit

Permalink
fix(generic): add exclude kwargs to not show deselected columns
Browse files Browse the repository at this point in the history
please note: this is not perfect as the `get_table_class` function
gets called twice. Its needed for filtering the kwargs of the table
but is not yet available when `get_table_kwargs` gets called.
  • Loading branch information
sennierer committed Mar 28, 2024
1 parent 416a98c commit cb48654
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion apis_core/generic/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,20 @@ def get_table_class(self):

def get_table_kwargs(self):
kwargs = super().get_table_kwargs()
columns = self.request.GET.getlist("columns", [])
columns = self.request.GET.getlist(
"columns", self.filterset.form.fields["columns"].initial
)
column_fields = [
field for field in self.model._meta.fields if field.name in columns
]
table_class = self.get_table_class()
kwargs["extra_columns"] = [
(field.name, library.column_for_field(field, accessor=field.name))
for field in column_fields
if field.name not in table_class.base_columns
]
kwargs["exclude"] = [
field.name for field in self.model._meta.fields if field.name not in columns
]
return kwargs

Expand Down

0 comments on commit cb48654

Please sign in to comment.