From 04b22e5002571abd00d1fc5bef8bc635025c8919 Mon Sep 17 00:00:00 2001 From: cell Date: Tue, 28 Feb 2006 00:50:06 +0000 Subject: [PATCH] magic-removal: laid groundwork for subclassing. git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2432 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/base.py | 11 +++++++++++ django/db/models/options.py | 1 + 2 files changed, 12 insertions(+) diff --git a/django/db/models/base.py b/django/db/models/base.py index b9e1faf593..1ec73209d8 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -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) diff --git a/django/db/models/options.py b/django/db/models/options.py index 667b2dcfc3..8e047dc2db 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -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__