magic-removal: laid groundwork for subclassing.
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2432 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
36bfffccc4
commit
04b22e5002
|
@ -35,6 +35,12 @@ class ModelBase(type):
|
|||
new_class.add_to_class('_meta', Options(attrs.pop('Meta', None)))
|
||||
new_class.add_to_class('DoesNotExist', types.ClassType('DoesNotExist', (ObjectDoesNotExist,), {}))
|
||||
|
||||
# Build complete list of parents
|
||||
for base in bases:
|
||||
if '_meta' in dir(base):
|
||||
new_class._meta.parents.append(base)
|
||||
new_class._meta.parents.extend(base._meta.parents)
|
||||
|
||||
model_module = sys.modules[new_class.__module__]
|
||||
|
||||
if getattr(new_class._meta, 'app_label', None) is None:
|
||||
|
@ -46,6 +52,11 @@ class ModelBase(type):
|
|||
for obj_name, obj in attrs.items():
|
||||
new_class.add_to_class(obj_name, obj)
|
||||
|
||||
# Add Fields inherited from parents
|
||||
for parent in new_class._meta.parents:
|
||||
for field in parent._meta.fields:
|
||||
field.contribute_to_class(new_class, field.name)
|
||||
|
||||
new_class._prepare()
|
||||
|
||||
register_models(new_class._meta.app_label, new_class)
|
||||
|
|
|
@ -31,6 +31,7 @@ class Options:
|
|||
self.pk = None
|
||||
self.has_auto_field = False
|
||||
self.one_to_one_field = None
|
||||
self.parents = []
|
||||
|
||||
def merge_meta(self):
|
||||
meta_attrs = self.meta.__dict__
|
||||
|
|
Loading…
Reference in New Issue