Skip to content

Commit 5666bca

Browse files
committed
Fixed #11369 -- Corrected verbose_name_plural model Meta option to be consistent with verbose_name when using abstract model inheritance. Thanks Beetle_B for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14588 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent 4276b51 commit 5666bca

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

django/db/models/options.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# Calculate the verbose_name by converting from InitialCaps to "lowercase with spaces".
2020
get_verbose_name = lambda class_name: re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))', ' \\1', class_name).lower().strip()
2121

22-
DEFAULT_NAMES = ('verbose_name', 'db_table', 'ordering',
22+
DEFAULT_NAMES = ('verbose_name', 'verbose_name_plural', 'db_table', 'ordering',
2323
'unique_together', 'permissions', 'get_latest_by',
2424
'order_with_respect_to', 'app_label', 'db_tablespace',
2525
'abstract', 'managed', 'proxy', 'auto_created')
@@ -91,7 +91,8 @@ def contribute_to_class(self, cls, name):
9191

9292
# verbose_name_plural is a special case because it uses a 's'
9393
# by default.
94-
self.verbose_name_plural = meta_attrs.pop('verbose_name_plural', string_concat(self.verbose_name, 's'))
94+
if self.verbose_name_plural is None:
95+
self.verbose_name_plural = string_concat(self.verbose_name, 's')
9596

9697
# Any leftover attributes must be invalid.
9798
if meta_attrs != {}:

tests/regressiontests/model_inheritance_regress/models.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,20 @@ def __unicode__(self):
103103
return "PK = %d, base_name = %s, derived_name = %s" \
104104
% (self.customPK, self.base_name, self.derived_name)
105105

106+
class AuditBase(models.Model):
107+
planned_date = models.DateField()
108+
109+
class Meta:
110+
abstract = True
111+
verbose_name_plural = u'Audits'
112+
113+
class CertificationAudit(AuditBase):
114+
class Meta(AuditBase.Meta):
115+
abstract = True
116+
117+
class InternalCertificationAudit(CertificationAudit):
118+
auditing_dept = models.CharField(max_length=20)
119+
106120
# Check that abstract classes don't get m2m tables autocreated.
107121
class Person(models.Model):
108122
name = models.CharField(max_length=100)

tests/regressiontests/model_inheritance_regress/tests.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
Place, Restaurant, ItalianRestaurant, ParkingLot, ParkingLot2,
99
ParkingLot3, Supplier, Wholesaler, Child, SelfRefChild, ArticleWithAuthor,
1010
M2MChild, QualityControl, DerivedM, Person, BirthdayParty, BachelorParty,
11-
MessyBachelorParty)
11+
MessyBachelorParty, InternalCertificationAudit)
1212

1313
class ModelInheritanceTest(TestCase):
1414
def test_model_inheritance(self):
@@ -353,3 +353,14 @@ def test_abstract_base_class_m2m_relation_inheritance(self):
353353

354354
parties = list(p4.bachelorparty_set.all())
355355
self.assertEqual(parties, [bachelor, messy_parent])
356+
357+
def test_11369(self):
358+
"""verbose_name_plural correctly inherited from ABC if inheritance chain includes an abstract model."""
359+
# Regression test for #11369: verbose_name_plural should be inherited
360+
# from an ABC even when there are one or more intermediate
361+
# abstract models in the inheritance chain, for consistency with
362+
# verbose_name.
363+
self.assertEquals(
364+
InternalCertificationAudit._meta.verbose_name_plural,
365+
u'Audits'
366+
)

0 commit comments

Comments
 (0)