Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django admin filter is broken for enum fields #75

Closed
jansegre opened this issue Jul 5, 2017 · 2 comments
Closed

Django admin filter is broken for enum fields #75

jansegre opened this issue Jul 5, 2017 · 2 comments

Comments

@jansegre
Copy link

jansegre commented Jul 5, 2017

The url that django generates for filers (field__exact=x) ends up using str(some_enum) instead of some_enum.value for x.

This is can be tested by adding a field_x (which is an enum field) to the filters = ('field_x',) of a registered model admin.

@jacebrowning
Copy link

jacebrowning commented Sep 27, 2017

The README says to use:

from enumfields.admin import EnumFieldListFilter

class MyModelAdmin(admin.ModelAdmin):
  list_filter = [('color', EnumFieldListFilter)]

which seems to work well combined with:

list_display = [
    ...
    '_color',
    ...
]

@staticmethod
def _color(obj):
    return obj.state

to force column values to be formatted the same as the filter.

@jansegre
Copy link
Author

Thanks! This is what I was looking for. I don't know how I missed it.

If there is normal any way to make this automatic I'd be glad to help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants