mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
[2.2.x] Fixed #30280 -- Restored Model.get_FIELD_display()'s coercion of lazy strings.
Revertedcc79c7ee63. Backport ofea071870f9from master.
This commit is contained in:
committed by
Tim Graham
parent
8cff329802
commit
a86ffb3e0f
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user