Right now we need to use EnumFieldListFilter like this:
from enumfields.admin import EnumFieldListFilter
class MyModelAdmin(admin.ModelAdmin):
list_filter = [('color', EnumFieldListFilter)]
It's easy to forget it (see #75 ).
But there is a better way. By using django's FieldListFilter.register we can "attach" the filter to the EnumField:
from django.contrib.admin.filters import FieldListFilter
from .fields import EnumFieldMixin
class EnumFieldListFilter(ChoicesFieldListFilter):
....
FieldListFilter.register(lambda f: isinstance(f, EnumFieldMixin), EnumFieldListFilter)
This should work with both EnumField and EnumIntegerField fields. The EnumFieldListFilter section in the README won't be needed anymore.
This should work for django > 1.4. For older versions there is a workaround.
Would you be interested in a pull request? These days I try to ask beforehand.
Right now we need to use EnumFieldListFilter like this:
It's easy to forget it (see #75 ).
But there is a better way. By using django's
FieldListFilter.registerwe can "attach" the filter to the EnumField:This should work with both EnumField and EnumIntegerField fields. The EnumFieldListFilter section in the README won't be needed anymore.
This should work for django > 1.4. For older versions there is a workaround.
Would you be interested in a pull request? These days I try to ask beforehand.