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

Fixed #33985 -- Used app_config.verbose_name in ContentType.__str__().

This commit is contained in:
Hrushikesh Vaidya 2022-09-13 19:00:57 +05:30 committed by Mariusz Felisiak
parent 18473004af
commit a52bdea5a2
5 changed files with 14 additions and 7 deletions

View File

@ -162,7 +162,10 @@ class ContentType(models.Model):
model = self.model_class() model = self.model_class()
if not model: if not model:
return self.model return self.model
return "%s | %s" % (model._meta.app_label, model._meta.verbose_name) return "%s | %s" % (
model._meta.app_config.verbose_name,
model._meta.verbose_name,
)
def model_class(self): def model_class(self):
"""Return the model class for this type of content.""" """Return the model class for this type of content."""

View File

@ -587,5 +587,5 @@ class PermissionTests(TestCase):
def test_str(self): def test_str(self):
p = Permission.objects.get(codename="view_customemailfield") p = Permission.objects.get(codename="view_customemailfield")
self.assertEqual( self.assertEqual(
str(p), "auth_tests | custom email field | Can view custom email field" str(p), "Auth_Tests | custom email field | Can view custom email field"
) )

View File

@ -280,7 +280,11 @@ class ContentTypesTests(TestCase):
def test_str(self): def test_str(self):
ct = ContentType.objects.get(app_label="contenttypes_tests", model="site") ct = ContentType.objects.get(app_label="contenttypes_tests", model="site")
self.assertEqual(str(ct), "contenttypes_tests | site") self.assertEqual(str(ct), "Contenttypes_Tests | site")
def test_str_auth(self):
ct = ContentType.objects.get(app_label="auth", model="group")
self.assertEqual(str(ct), "Authentication and Authorization | group")
def test_name(self): def test_name(self):
ct = ContentType.objects.get(app_label="contenttypes_tests", model="site") ct = ContentType.objects.get(app_label="contenttypes_tests", model="site")
@ -288,7 +292,7 @@ class ContentTypesTests(TestCase):
def test_app_labeled_name(self): def test_app_labeled_name(self):
ct = ContentType.objects.get(app_label="contenttypes_tests", model="site") ct = ContentType.objects.get(app_label="contenttypes_tests", model="site")
self.assertEqual(ct.app_labeled_name, "contenttypes_tests | site") self.assertEqual(ct.app_labeled_name, "Contenttypes_Tests | site")
def test_name_unknown_model(self): def test_name_unknown_model(self):
ct = ContentType(app_label="contenttypes_tests", model="unknown") ct = ContentType(app_label="contenttypes_tests", model="unknown")

View File

@ -20,6 +20,6 @@ class ContentTypeTests(TestCase):
def test_verbose_name(self): def test_verbose_name(self):
company_type = ContentType.objects.get(app_label="i18n", model="company") company_type = ContentType.objects.get(app_label="i18n", model="company")
with translation.override("en"): with translation.override("en"):
self.assertEqual(str(company_type), "i18n | Company") self.assertEqual(str(company_type), "I18N | Company")
with translation.override("fr"): with translation.override("fr"):
self.assertEqual(str(company_type), "i18n | Société") self.assertEqual(str(company_type), "I18N | Société")

View File

@ -1118,7 +1118,7 @@ class QueryTestCase(TestCase):
# Set a foreign key with an object from a different database # Set a foreign key with an object from a different database
msg = ( msg = (
'Cannot assign "<ContentType: multiple_database | book>": the ' 'Cannot assign "<ContentType: Multiple_Database | book>": the '
"current database router prevents this relation." "current database router prevents this relation."
) )
with self.assertRaisesMessage(ValueError, msg): with self.assertRaisesMessage(ValueError, msg):