magic-removal: Added helpful error message if a model contains a field named 'Admin' that isn't admin settings
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2020 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
2a04bb9b58
commit
ae4f89436f
|
@ -32,11 +32,11 @@ class ModelBase(type):
|
|||
new_class.add_to_class('_meta', Options(attrs.pop('Meta', None)))
|
||||
new_class.add_to_class('DoesNotExist', types.ClassType('DoesNotExist', (ObjectDoesNotExist,), {}))
|
||||
|
||||
#Figure out the app_label by looking one level up.
|
||||
#FIXME: wrong for nested model modules
|
||||
app_package = sys.modules.get(new_class.__module__)
|
||||
app_label = app_package.__name__.replace('.models', '')
|
||||
app_label = app_label[app_label.rfind('.')+1:]
|
||||
|
||||
# Figure out the app_label by looking one level up.
|
||||
# For 'django.contrib.sites.models', this would be 'sites'.
|
||||
app_label = app_package.__name__.split('.')[-2]
|
||||
|
||||
# Cache the app label.
|
||||
new_class._meta.app_label = app_label
|
||||
|
@ -108,6 +108,7 @@ class Model(object):
|
|||
|
||||
def add_to_class(cls, name, value):
|
||||
if name == 'Admin':
|
||||
assert type(value) == types.ClassType, "%r attribute of %s model must be a class, not a %s object" % (name, cls.__name__, type(value))
|
||||
value = AdminOptions(**dict([(k, v) for k, v in value.__dict__.items() if not k.startswith('_')]))
|
||||
if hasattr(value, 'contribute_to_class'):
|
||||
value.contribute_to_class(cls, name)
|
||||
|
|
Loading…
Reference in New Issue