Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 5666bca67872a628631642743375d31956f24a2f 1 parent 4276b51
Ramiro Morales authored November 17, 2010
5  django/db/models/options.py
@@ -19,7 +19,7 @@
19 19
 # Calculate the verbose_name by converting from InitialCaps to "lowercase with spaces".
20 20
 get_verbose_name = lambda class_name: re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))', ' \\1', class_name).lower().strip()
21 21
 
22  
-DEFAULT_NAMES = ('verbose_name', 'db_table', 'ordering',
  22
+DEFAULT_NAMES = ('verbose_name', 'verbose_name_plural', 'db_table', 'ordering',
23 23
                  'unique_together', 'permissions', 'get_latest_by',
24 24
                  'order_with_respect_to', 'app_label', 'db_tablespace',
25 25
                  'abstract', 'managed', 'proxy', 'auto_created')
@@ -91,7 +91,8 @@ def contribute_to_class(self, cls, name):
91 91
 
92 92
             # verbose_name_plural is a special case because it uses a 's'
93 93
             # 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')
95 96
 
96 97
             # Any leftover attributes must be invalid.
97 98
             if meta_attrs != {}:
14  tests/regressiontests/model_inheritance_regress/models.py
@@ -103,6 +103,20 @@ def __unicode__(self):
103 103
         return "PK = %d, base_name = %s, derived_name = %s" \
104 104
                 % (self.customPK, self.base_name, self.derived_name)
105 105
 
  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
+
106 120
 # Check that abstract classes don't get m2m tables autocreated.
107 121
 class Person(models.Model):
108 122
     name = models.CharField(max_length=100)
13  tests/regressiontests/model_inheritance_regress/tests.py
@@ -8,7 +8,7 @@
8 8
     Place, Restaurant, ItalianRestaurant, ParkingLot, ParkingLot2,
9 9
     ParkingLot3, Supplier, Wholesaler, Child, SelfRefChild, ArticleWithAuthor,
10 10
     M2MChild, QualityControl, DerivedM, Person, BirthdayParty, BachelorParty,
11  
-    MessyBachelorParty)
  11
+    MessyBachelorParty, InternalCertificationAudit)
12 12
 
13 13
 class ModelInheritanceTest(TestCase):
14 14
     def test_model_inheritance(self):
@@ -353,3 +353,14 @@ def test_abstract_base_class_m2m_relation_inheritance(self):
353 353
 
354 354
         parties = list(p4.bachelorparty_set.all())
355 355
         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 notes on commit 5666bca

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