Changed ModelFormMetaclass to have the normal signature for a __new__ method.
Allows extending the metaclass more normally. Patch from Christian Tanzer. Refs #7617. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7847 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
0d0cbfd56e
commit
075098f9fd
|
@ -213,18 +213,19 @@ class ModelFormOptions(object):
|
||||||
|
|
||||||
|
|
||||||
class ModelFormMetaclass(type):
|
class ModelFormMetaclass(type):
|
||||||
def __new__(cls, name, bases, attrs,
|
def __new__(cls, name, bases, attrs):
|
||||||
formfield_callback=lambda f: f.formfield()):
|
formfield_callback = attrs.pop('formfield_callback',
|
||||||
|
lambda f: f.formfield())
|
||||||
try:
|
try:
|
||||||
parents = [b for b in bases if issubclass(b, ModelForm)]
|
parents = [b for b in bases if issubclass(b, ModelForm)]
|
||||||
except NameError:
|
except NameError:
|
||||||
# We are defining ModelForm itself.
|
# We are defining ModelForm itself.
|
||||||
parents = None
|
parents = None
|
||||||
if not parents:
|
new_class = super(ModelFormMetaclass, cls).__new__(cls, name, bases,
|
||||||
return super(ModelFormMetaclass, cls).__new__(cls, name, bases,
|
|
||||||
attrs)
|
attrs)
|
||||||
|
if not parents:
|
||||||
|
return new_class
|
||||||
|
|
||||||
new_class = type.__new__(cls, name, bases, attrs)
|
|
||||||
declared_fields = get_declared_fields(bases, attrs, False)
|
declared_fields = get_declared_fields(bases, attrs, False)
|
||||||
opts = new_class._meta = ModelFormOptions(getattr(new_class, 'Meta', None))
|
opts = new_class._meta = ModelFormOptions(getattr(new_class, 'Meta', None))
|
||||||
if opts.model:
|
if opts.model:
|
||||||
|
|
Loading…
Reference in New Issue