JobDoesburg / django-admin-multi-select-filter

Django admin filter for multiple select
https://pypi.org/project/django-admin-multi-select-filter/
MIT License
11 stars 2 forks source link

support `django-choices-field` in `field_verboses` #6

Open replygirl opened 2 months ago

replygirl commented 2 months ago

using bellini666/django-choices-field, i have an integer field defined like:

class FooRole(models.IntegerChoices):
  FOO = 0, "Foo"
  BAR = 1, "Bar"
  BAZ = 2, "Baz"
  QUX = 3, "Qux"

class FooModel(models.Model)
  role = IntegerChoicesField(
    choices_enum=WorkspaceUserRole, default=FooRole.FOO
  )

...which when used with MultiSelectFieldListFilter looks like:

Screenshot 2024-08-20 at 5 59 17 PM

i think the labels from the fields in django-choices-field could be used if this lookup on self.field.choices could fall back to self.field.choices_enum.choices:

self.field_verboses = {
  field_value: field_verbose
  for field_value, field_verbose in self.field.choices
}
JobDoesburg commented 1 month ago

If you open a PR I will gladly accept the change!