Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.2.X] Fixed #11369 -- Corrected verbose_name_plural model Meta opti…

…on to be consistent with verbose_name when using abstract model inheritance. Thanks Beetle_B for the report.

Backport of [14588] from trunk

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14589 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 8acad926df509863c9b701d32c1b4a90e7e0a229 1 parent 03b111c
@ramiro ramiro authored
View
5 django/db/models/options.py
@@ -14,7 +14,7 @@
# Calculate the verbose_name by converting from InitialCaps to "lowercase with spaces".
get_verbose_name = lambda class_name: re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))', ' \\1', class_name).lower().strip()
-DEFAULT_NAMES = ('verbose_name', 'db_table', 'ordering',
+DEFAULT_NAMES = ('verbose_name', 'verbose_name_plural', 'db_table', 'ordering',
'unique_together', 'permissions', 'get_latest_by',
'order_with_respect_to', 'app_label', 'db_tablespace',
'abstract', 'managed', 'proxy', 'auto_created')
@@ -86,7 +86,8 @@ def contribute_to_class(self, cls, name):
# verbose_name_plural is a special case because it uses a 's'
# by default.
- setattr(self, 'verbose_name_plural', meta_attrs.pop('verbose_name_plural', string_concat(self.verbose_name, 's')))
+ if self.verbose_name_plural is None:
+ self.verbose_name_plural = string_concat(self.verbose_name, 's')
# Any leftover attributes must be invalid.
if meta_attrs != {}:
View
14 tests/regressiontests/model_inheritance_regress/models.py
@@ -103,6 +103,20 @@ def __unicode__(self):
return "PK = %d, base_name = %s, derived_name = %s" \
% (self.customPK, self.base_name, self.derived_name)
+class AuditBase(models.Model):
+ planned_date = models.DateField()
+
+ class Meta:
+ abstract = True
+ verbose_name_plural = u'Audits'
+
+class CertificationAudit(AuditBase):
+ class Meta(AuditBase.Meta):
+ abstract = True
+
+class InternalCertificationAudit(CertificationAudit):
+ auditing_dept = models.CharField(max_length=20)
+
# Check that abstract classes don't get m2m tables autocreated.
class Person(models.Model):
name = models.CharField(max_length=100)
View
13 tests/regressiontests/model_inheritance_regress/tests.py
@@ -8,7 +8,7 @@
Place, Restaurant, ItalianRestaurant, ParkingLot, ParkingLot2,
ParkingLot3, Supplier, Wholesaler, Child, SelfRefChild, ArticleWithAuthor,
M2MChild, QualityControl, DerivedM, Person, BirthdayParty, BachelorParty,
- MessyBachelorParty)
+ MessyBachelorParty, InternalCertificationAudit)
class ModelInheritanceTest(TestCase):
def test_model_inheritance(self):
@@ -353,3 +353,14 @@ def test_abstract_base_class_m2m_relation_inheritance(self):
parties = list(p4.bachelorparty_set.all())
self.assertEqual(parties, [bachelor, messy_parent])
+
+ def test_11369(self):
+ """verbose_name_plural correctly inherited from ABC if inheritance chain includes an abstract model."""
+ # Regression test for #11369: verbose_name_plural should be inherited
+ # from an ABC even when there are one or more intermediate
+ # abstract models in the inheritance chain, for consistency with
+ # verbose_name.
+ self.assertEquals(
+ InternalCertificationAudit._meta.verbose_name_plural,
+ u'Audits'
+ )

0 comments on commit 8acad92

Please sign in to comment.
Something went wrong with that request. Please try again.