1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Fixed #35232 -- Cached model's Options.verbose_name_raw.

This commit is contained in:
Adam Johnson 2024-02-18 21:49:25 +00:00 committed by Mariusz Felisiak
parent 28a3fbe004
commit f25d84f61a
3 changed files with 18 additions and 1 deletions

View File

@ -395,9 +395,11 @@ class Options:
)
return True
@property
@cached_property
def verbose_name_raw(self):
"""Return the untranslated verbose name."""
if isinstance(self.verbose_name, str):
return self.verbose_name
with override(None):
return str(self.verbose_name)

View File

@ -1,6 +1,7 @@
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.utils.translation import gettext_lazy as _
class Relation(models.Model):
@ -124,6 +125,9 @@ class Person(BasePerson):
# GR fields
generic_relation_concrete = GenericRelation(Relation)
class Meta:
verbose_name = _("Person")
class ProxyPerson(Person):
class Meta:

View File

@ -222,6 +222,17 @@ class GetFieldByNameTests(OptionsBaseTests):
opts.apps.models_ready = True
class VerboseNameRawTests(SimpleTestCase):
def test_string(self):
# Clear cached property.
Relation._meta.__dict__.pop("verbose_name_raw", None)
self.assertEqual(Relation._meta.verbose_name_raw, "relation")
def test_gettext(self):
Person._meta.__dict__.pop("verbose_name_raw", None)
self.assertEqual(Person._meta.verbose_name_raw, "Person")
class RelationTreeTests(SimpleTestCase):
all_models = (Relation, AbstractPerson, BasePerson, Person, ProxyPerson, Relating)