Tuesday, April 4, 2023

Django Admin does not use `get_FOO_display`

I had a model having a field that uses Choices 
    status = FSMField(default=STATUSES.PENDING, choices=STATUSES, protected=True)

I did override  the `get_status_display ` and its effect was not applied in the Django admin  

I looked up Django code and found 
```
def display_for_field(value, field, empty_value_display): from django.contrib.admin.templatetags.admin_list import _boolean_icon if getattr(field, "flatchoices", None): return dict(field.flatchoices).get(value, empty_value_display)
``` I changed it to use get_FOO_display and it worked,
my question is why does it have this behavior? and how in my application can I make use of this?

Thank you.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7dabd818-4b70-409e-8af3-482dffffeb3an%40googlegroups.com.

No comments:

Post a Comment