Code

Ticket #1552: options_fix_r2592.diff

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

Add default for verbose_name_plural

Line 
1=== django/db/models/options.py
2==================================================================
3--- django/db/models/options.py (revision 2659)
4+++ django/db/models/options.py (local)
5@@ -10,7 +10,7 @@
6 # Calculate the verbose_name by converting from InitialCaps to "lowercase with spaces".
7 get_verbose_name = lambda class_name: re.sub('([A-Z])', ' \\1', class_name).lower().strip()
8 
9-DEFAULT_NAMES = ('verbose_name', 'db_table', 'ordering',
10+DEFAULT_NAMES = ('verbose_name', 'verbose_name_plural', 'db_table', 'ordering',
11                  'unique_together', 'permissions', 'get_latest_by',
12                  'order_with_respect_to', 'app_label')
13 
14@@ -39,16 +39,16 @@
15         self.object_name = cls.__name__
16         self.module_name = self.object_name.lower()
17         self.verbose_name = get_verbose_name(self.object_name)
18+        self.verbose_name_plural = self.verbose_name + 's'
19         # Next, apply any overridden values from 'class Meta'.
20         if self.meta:
21             meta_attrs = self.meta.__dict__
22             del meta_attrs['__module__']
23             del meta_attrs['__doc__']
24+            if 'verbose_name' in meta_attrs and 'verbose_name_plural' not in meta_attrs:
25+                meta_attrs['verbose_name_plural'] = meta_attrs['verbose_name'] + 's'
26             for attr_name in DEFAULT_NAMES:
27                 setattr(self, attr_name, meta_attrs.pop(attr_name, getattr(self, attr_name)))
28-            # verbose_name_plural is a special case because it uses a 's'
29-            # by default.
30-            setattr(self, 'verbose_name_plural', meta_attrs.pop('verbose_name_plural', self.verbose_name + 's'))
31             # Any leftover attributes must be invalid.
32             if meta_attrs != {}:
33                 raise TypeError, "'class Meta' got invalid attribute(s): %s" % ','.join(meta_attrs.keys())