* stage: Unreviewed => Accepted
Comment:
Thanks for the report. `ArrayField` must have `choices` to reproduce this
issue, e.g.
{{{#!python
field_2 = ArrayField(models.IntegerField(), choices=[
([1, 2, 3], "base choice"),
([1, 2], "1st choice"),
([2, 3], "2nd choice"),
])
}}}
We could try to call `make_hashable()` on the `flatchoices` and `value`:
{{{#!diff
diff --git a/django/contrib/admin/utils.py b/django/contrib/admin/utils.py
index 6cb549fb10..3e09153138 100644
--- a/django/contrib/admin/utils.py
+++ b/django/contrib/admin/utils.py
@@ -10,6 +10,7 @@ from django.db.models.deletion import Collector
from django.forms.utils import pretty_name
from django.urls import NoReverseMatch, reverse
from django.utils import formats, timezone
+from django.utils.hashable import make_hashable
from django.utils.html import format_html
from django.utils.regex_helper import _lazy_re_compile
from django.utils.text import capfirst
@@ -401,7 +402,7 @@ 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)
+ return
dict(make_hashable(field.flatchoices)).get(make_hashable(value),
empty_value_display)
# BooleanField needs special-case null-handling, so it comes before
the
# general null test.
elif isinstance(field, models.BooleanField):
}}}
but this can cause a performance regression.
--
Ticket URL: <https://code.djangoproject.com/ticket/33927#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.