Skip to content

Commit

Permalink
fix(generic): include ManyToManyFields in list view
Browse files Browse the repository at this point in the history
Switch from `fields` method, which is meant to be used by Django
internally, to `get_fields` method to include ManyToManyFields
in "additional columns" dropdown.
Fall back to using field name as label in the UI for fields
without `verbose_name`.

Closes: #1020
  • Loading branch information
koeaw committed Jul 2, 2024
1 parent d0bffdb commit 2763e0e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions apis_core/generic/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def get_table_kwargs(self):
if self.request.GET
else self.get_filterset(self.get_filterset_class()).form["columns"].initial
)
modelfields = self.model._meta.fields
modelfields = self.model._meta.get_fields()
kwargs["exclude"] = [
field.name for field in modelfields if field.name not in selected_columns
]
Expand Down Expand Up @@ -150,7 +150,8 @@ def get_filterset_class(self):
def _get_columns_choices(self, columns_exclude):
# we start with the model fields
choices = [
(field.name, field.verbose_name) for field in self.model._meta.fields
(field.name, getattr(field, "verbose_name", field.name))
for field in self.model._meta.get_fields()
]
# we add any annotated fields to that
choices += [(key, key) for key in self.get_queryset().query.annotations.keys()]
Expand Down

0 comments on commit 2763e0e

Please sign in to comment.