From c44fd057fa3a1e36aac09a08accb7840c583abaf Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Mon, 26 Sep 2005 05:12:22 +0000 Subject: [PATCH] Subclassed models now use their own class name (or explicitly defined verbose_name) as the verbose_name, not the parent's verbose_name. See also #558 and [697]. git-svn-id: http://code.djangoproject.com/svn/django/trunk@698 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/meta/__init__.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/django/core/meta/__init__.py b/django/core/meta/__init__.py index 8061394dde..3ca42f14e6 100644 --- a/django/core/meta/__init__.py +++ b/django/core/meta/__init__.py @@ -385,6 +385,12 @@ def _reassign_globals(function_dict, extra_globals, namespace): new_v.func_globals[k] = func new_functions[k] = func +# Calculate the module_name using a poor-man's pluralization. +get_module_name = lambda class_name: class_name.lower() + 's' + +# 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() + class ModelBase(type): "Metaclass for all models" def __new__(cls, name, bases, attrs): @@ -430,7 +436,7 @@ class ModelBase(type): # Pass any Options overrides to the base's Options instance, and # simultaneously remove them from attrs. When this is done, attrs # will be a dictionary of custom methods, plus __module__. - meta_overrides = {'fields': fields, 'module_name': name.lower() + 's'} + meta_overrides = {'fields': fields, 'module_name': get_module_name(name), 'verbose_name': get_verbose_name(name)} for k, v in meta_attrs.items(): if not callable(v) and k != '__module__': meta_overrides[k] = meta_attrs.pop(k) @@ -439,14 +445,10 @@ class ModelBase(type): del meta_overrides else: opts = Options( - # If the module_name wasn't given, use the class name - # in lowercase, plus a trailing "s" -- a poor-man's - # pluralization. - module_name = meta_attrs.pop('module_name', name.lower() + 's'), + module_name = meta_attrs.pop('module_name', get_module_name(name)), # If the verbose_name wasn't given, use the class name, # converted from InitialCaps to "lowercase with spaces". - verbose_name = meta_attrs.pop('verbose_name', - re.sub('([A-Z])', ' \\1', name).lower().strip()), + verbose_name = meta_attrs.pop('verbose_name', get_verbose_name(name)), verbose_name_plural = meta_attrs.pop('verbose_name_plural', ''), db_table = meta_attrs.pop('db_table', ''), fields = fields,