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
This commit is contained in:
parent
e2740dd400
commit
0d0cbfd56e
1
AUTHORS
1
AUTHORS
|
@ -350,6 +350,7 @@ answer newbie questions, and generally made Django that much better:
|
||||||
Swaroop C H <http://www.swaroopch.info>
|
Swaroop C H <http://www.swaroopch.info>
|
||||||
Aaron Swartz <http://www.aaronsw.com/>
|
Aaron Swartz <http://www.aaronsw.com/>
|
||||||
Ville Säävuori <http://www.unessa.net/>
|
Ville Säävuori <http://www.unessa.net/>
|
||||||
|
Christian Tanzer <tanzer@swing.co.at>
|
||||||
Tyler Tarabula <tyler.tarabula@gmail.com>
|
Tyler Tarabula <tyler.tarabula@gmail.com>
|
||||||
Tyson Tate <tyson@fallingbullets.com>
|
Tyson Tate <tyson@fallingbullets.com>
|
||||||
Frank Tegtmeyer <fte@fte.to>
|
Frank Tegtmeyer <fte@fte.to>
|
||||||
|
|
|
@ -31,19 +31,15 @@ except NameError:
|
||||||
class ModelBase(type):
|
class ModelBase(type):
|
||||||
"Metaclass for all models"
|
"Metaclass for all models"
|
||||||
def __new__(cls, name, bases, attrs):
|
def __new__(cls, name, bases, attrs):
|
||||||
# If this isn't a subclass of Model, don't do anything special.
|
super_new = super(ModelBase, cls).__new__
|
||||||
try:
|
parents = [b for b in bases if isinstance(b, ModelBase)]
|
||||||
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 = []
|
|
||||||
if not parents:
|
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.
|
# Create the class.
|
||||||
module = attrs.pop('__module__')
|
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)
|
attr_meta = attrs.pop('Meta', None)
|
||||||
abstract = getattr(attr_meta, 'abstract', False)
|
abstract = getattr(attr_meta, 'abstract', False)
|
||||||
if not attr_meta:
|
if not attr_meta:
|
||||||
|
|
|
@ -56,7 +56,8 @@ class DeclarativeFieldsMetaclass(type):
|
||||||
"""
|
"""
|
||||||
def __new__(cls, name, bases, attrs):
|
def __new__(cls, name, bases, attrs):
|
||||||
attrs['base_fields'] = get_declared_fields(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):
|
class BaseForm(StrAndUnicode):
|
||||||
# This is the main implementation of all the Form logic. Note that this
|
# This is the main implementation of all the Form logic. Note that this
|
||||||
|
|
Loading…
Reference in New Issue