From 652a05777e40c825cade289001dd74aa500c8ad6 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Mon, 27 Mar 2006 23:20:59 +0000 Subject: [PATCH] magic-removal: Fixed Option.verbose_name_plural behavior so that it's always calculated based on verbose_name, regardless of whether a custom verbose_name was given. Thanks for reporting, ChaosKCW git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2571 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/options.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/django/db/models/options.py b/django/db/models/options.py index 93109bd4e3..335c92c52a 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -10,7 +10,7 @@ import re # Calculate the verbose_name by converting from InitialCaps to "lowercase with spaces". get_verbose_name = lambda class_name: re.sub('([A-Z])', ' \\1', class_name).lower().strip() -DEFAULT_NAMES = ('verbose_name', 'verbose_name_plural', 'db_table', 'ordering', +DEFAULT_NAMES = ('verbose_name', 'db_table', 'ordering', 'unique_together', 'permissions', 'get_latest_by', 'order_with_respect_to', 'app_label') @@ -35,18 +35,21 @@ class Options: def contribute_to_class(self, cls, name): cls._meta = self + # First, construct the default values for these options. self.object_name = cls.__name__ self.module_name = self.object_name.lower() - # If the verbose_name wasn't given, use the class name, - # converted from "InitialCaps" to "lowercase with spaces". self.verbose_name = get_verbose_name(self.object_name) - self.verbose_name_plural = self.verbose_name + 's' + # Next, apply any overridden values from 'class Meta'. if self.meta: meta_attrs = self.meta.__dict__ del meta_attrs['__module__'] del meta_attrs['__doc__'] for attr_name in DEFAULT_NAMES: setattr(self, attr_name, meta_attrs.pop(attr_name, getattr(self, attr_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', self.verbose_name + 's')) + # Any leftover attributes must be invalid. if meta_attrs != {}: raise TypeError, "'class Meta' got invalid attribute(s): %s" % ','.join(meta_attrs.keys()) del self.meta