1
0
mirror of https://github.com/django/django.git synced 2024-12-25 18:46:22 +00:00

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
This commit is contained in:
Adrian Holovaty 2005-09-26 05:12:22 +00:00
parent 60bb739d9e
commit c44fd057fa

View File

@ -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,