Skip to content

Commit

Permalink
fix(generic): exclude subclasses from columns selector
Browse files Browse the repository at this point in the history
We don't want to list subclasses as model attribute in the column
selector in the list view, but they are part of the fields list. If the
model uses the InheritanceManager we can check in the `subclasses`
attribute if the field refers to a subclass and exclude those.

Closes: #1297
  • Loading branch information
b1rger committed Dec 4, 2024
1 parent 10c524e commit c64a152
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions apis_core/generic/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def _get_columns_choices(self, columns_exclude):
choices = [
(field.name, pretty_name(getattr(field, "verbose_name", field.name)))
for field in self.model._meta.get_fields()
if field.name not in getattr(self.get_queryset(), "subclasses", [])
]
# 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 c64a152

Please sign in to comment.