Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit c44fd057fa3a1e36aac09a08accb7840c583abaf 1 parent 60bb739
Adrian Holovaty adrianholovaty authored
Showing with 9 additions and 7 deletions.
  1. +9 −7 django/core/meta/__init__.py
16 django/core/meta/__init__.py
View
@@ -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 @@ def __new__(cls, name, bases, attrs):
# 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 @@ def __new__(cls, name, bases, attrs):
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,
Please sign in to comment.
Something went wrong with that request. Please try again.