summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMatthias Kestenholz <mk@feinheit.ch>2019-03-22 13:21:00 +0100
committerTim Graham <timograham@gmail.com>2019-03-22 12:30:10 -0400
commitea071870f943c23a8eaf36dfcdf382afd6478fd1 (patch)
tree3c127e046262b7f073c2a0b5d4345ecdc621a236 /django
parentd26b2424437dabeeca94d7900b37d2df4410da0c (diff)
Fixed #30280 -- Restored Model.get_FIELD_display()'s coercion of lazy strings.
Reverted cc79c7ee637e65c8da27e56d746c87903d5ec901.
Diffstat (limited to 'django')
-rw-r--r--django/db/models/base.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py
index 1ee97eb128..f2560117d2 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -28,6 +28,7 @@ from django.db.models.signals import (
class_prepared, post_init, post_save, pre_init, pre_save,
)
from django.db.models.utils import make_model_tuple
+from django.utils.encoding import force_str
from django.utils.text import capfirst, get_text_list
from django.utils.translation import gettext_lazy as _
from django.utils.version import get_version
@@ -921,7 +922,8 @@ class Model(metaclass=ModelBase):
def _get_FIELD_display(self, field):
value = getattr(self, field.attname)
- return dict(field.flatchoices).get(value, value)
+ # force_str() to coerce lazy strings.
+ return force_str(dict(field.flatchoices).get(value, value), strings_only=True)
def _get_next_or_previous_by_FIELD(self, field, is_next, **kwargs):
if not self.pk: