Ticket #1552: options_fix_r2592.diff

File options_fix_r2592.diff, 1.8 KB (added by django@…, 9 years ago)

Add default for verbose_name_plural

  • django/db/models/options.py

    === django/db/models/options.py
    ==================================================================
     
    1010# Calculate the verbose_name by converting from InitialCaps to "lowercase with spaces".
    1111get_verbose_name = lambda class_name: re.sub('([A-Z])', ' \\1', class_name).lower().strip()
    1212
    13 DEFAULT_NAMES = ('verbose_name', 'db_table', 'ordering',
     13DEFAULT_NAMES = ('verbose_name', 'verbose_name_plural', 'db_table', 'ordering',
    1414                 'unique_together', 'permissions', 'get_latest_by',
    1515                 'order_with_respect_to', 'app_label')
    1616
     
    3939        self.object_name = cls.__name__
    4040        self.module_name = self.object_name.lower()
    4141        self.verbose_name = get_verbose_name(self.object_name)
     42        self.verbose_name_plural = self.verbose_name + 's'
    4243        # Next, apply any overridden values from 'class Meta'.
    4344        if self.meta:
    4445            meta_attrs = self.meta.__dict__
    4546            del meta_attrs['__module__']
    4647            del meta_attrs['__doc__']
     48            if 'verbose_name' in meta_attrs and 'verbose_name_plural' not in meta_attrs:
     49                meta_attrs['verbose_name_plural'] = meta_attrs['verbose_name'] + 's'
    4750            for attr_name in DEFAULT_NAMES:
    4851                setattr(self, attr_name, meta_attrs.pop(attr_name, getattr(self, attr_name)))
    49             # verbose_name_plural is a special case because it uses a 's'
    50             # by default.
    51             setattr(self, 'verbose_name_plural', meta_attrs.pop('verbose_name_plural', self.verbose_name + 's'))
    5252            # Any leftover attributes must be invalid.
    5353            if meta_attrs != {}:
    5454                raise TypeError, "'class Meta' got invalid attribute(s): %s" % ','.join(meta_attrs.keys())
Back to Top