From 26f7d95ad9b52618ca02055ee5d6ee168a8c4a45 Mon Sep 17 00:00:00 2001 From: mtredinnick Date: Sun, 6 Jul 2008 11:55:30 +0000 Subject: [PATCH] Fixed #7621 -- Enable superclassing of the various metaclasses we use. Also tidy up some initialisation code in django.db.models.base.ModelBase. Thanks, Christian Tanzer. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7846 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- AUTHORS | 1 + django/db/models/base.py | 14 +++++--------- django/newforms/forms.py | 3 ++- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/AUTHORS b/AUTHORS index 164ec50404..c902404f3c 100644 --- a/AUTHORS +++ b/AUTHORS @@ -350,6 +350,7 @@ answer newbie questions, and generally made Django that much better: Swaroop C H Aaron Swartz Ville Säävuori + Christian Tanzer Tyler Tarabula Tyson Tate Frank Tegtmeyer diff --git a/django/db/models/base.py b/django/db/models/base.py index 5669694a1b..5e92a5adc1 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -31,19 +31,15 @@ class ModelBase(type): "Metaclass for all models" def __new__(cls, name, bases, attrs): - # If this isn't a subclass of Model, don't do anything special. - try: - parents = [b for b in bases if issubclass(b, Model)] - except NameError: - # 'Model' isn't defined yet, meaning we're looking at Django's own - # Model class, defined below. - parents = [] + super_new = super(ModelBase, cls).__new__ + parents = [b for b in bases if isinstance(b, ModelBase)] if not parents: - return super(ModelBase, cls).__new__(cls, name, bases, attrs) + # If this isn't a subclass of Model, don't do anything special. + return super_new(cls, name, bases, attrs) # Create the class. module = attrs.pop('__module__') - new_class = type.__new__(cls, name, bases, {'__module__': module}) + new_class = super_new(cls, name, bases, {'__module__': module}) attr_meta = attrs.pop('Meta', None) abstract = getattr(attr_meta, 'abstract', False) if not attr_meta: diff --git a/django/newforms/forms.py b/django/newforms/forms.py index 2c481e47a8..fc203f36b5 100644 --- a/django/newforms/forms.py +++ b/django/newforms/forms.py @@ -56,7 +56,8 @@ class DeclarativeFieldsMetaclass(type): """ def __new__(cls, name, bases, attrs): attrs['base_fields'] = get_declared_fields(bases, attrs) - return type.__new__(cls, name, bases, attrs) + return super(DeclarativeFieldsMetaclass, + cls).__new__(cls, name, bases, attrs) class BaseForm(StrAndUnicode): # This is the main implementation of all the Form logic. Note that this