1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

[2.2.x] Fixed #30280 -- Restored Model.get_FIELD_display()'s coercion of lazy strings.

Reverted cc79c7ee63.

Backport of ea071870f9 from master.
This commit is contained in:
Matthias Kestenholz
2019-03-22 13:21:00 +01:00
committed by Tim Graham
parent 8cff329802
commit a86ffb3e0f
3 changed files with 9 additions and 3 deletions

View File

@@ -10,12 +10,13 @@ field. This method returns the "human-readable" value of the field.
"""
from django.db import models
from django.utils.translation import gettext_lazy as _
class Person(models.Model):
GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female'),
('M', _('Male')),
('F', _('Female')),
)
name = models.CharField(max_length=20)
gender = models.CharField(max_length=1, choices=GENDER_CHOICES)

View File

@@ -20,3 +20,6 @@ class ChoicesTests(TestCase):
a.gender = 'U'
self.assertEqual(a.get_gender_display(), 'U')
# _get_FIELD_display() coerces lazy strings.
self.assertIsInstance(a.get_gender_display(), str)