1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #24858 -- Added support for get_FOO_display() to ArrayField and RangeFields.

_get_FIELD_display() crashed when Field.choices was unhashable.
This commit is contained in:
Hasan Ramezani
2019-11-07 15:35:33 +01:00
committed by Mariusz Felisiak
parent 8058d9d7ad
commit 153c7956f8
5 changed files with 84 additions and 1 deletions

View File

@@ -33,6 +33,7 @@ from django.db.models.signals import (
)
from django.db.models.utils import make_model_tuple
from django.utils.encoding import force_str
from django.utils.hashable import make_hashable
from django.utils.text import capfirst, get_text_list
from django.utils.translation import gettext_lazy as _
from django.utils.version import get_version
@@ -940,8 +941,9 @@ class Model(metaclass=ModelBase):
def _get_FIELD_display(self, field):
value = getattr(self, field.attname)
choices_dict = dict(make_hashable(field.flatchoices))
# force_str() to coerce lazy strings.
return force_str(dict(field.flatchoices).get(value, value), strings_only=True)
return force_str(choices_dict.get(make_hashable(value), value), strings_only=True)
def _get_next_or_previous_by_FIELD(self, field, is_next, **kwargs):
if not self.pk: