Commit 5666bca6 authored by Ramiro Morales's avatar Ramiro Morales
Browse files

Fixed #11369 -- Corrected verbose_name_plural model Meta option to be...

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
parent 4276b519
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ except NameError:
# 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')
@@ -91,7 +91,8 @@ class Options(object):

            # verbose_name_plural is a special case because it uses a 's'
            # by default.
            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 != {}:
+14 −0
Original line number Diff line number Diff line
@@ -103,6 +103,20 @@ class DerivedM(BaseM):
        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)
+12 −1
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ from regressiontests.model_inheritance_regress.models import (
    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 @@ class ModelInheritanceTest(TestCase):

        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'
        )