From 075098f9fd06c42faaba01ec8f855f4d4e99dae6 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Sun, 6 Jul 2008 12:29:40 +0000 Subject: [PATCH] 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 --- django/newforms/models.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/django/newforms/models.py b/django/newforms/models.py index eb6d01e787..c3938d9ae7 100644 --- a/django/newforms/models.py +++ b/django/newforms/models.py @@ -213,18 +213,19 @@ class ModelFormOptions(object): class ModelFormMetaclass(type): - def __new__(cls, name, bases, attrs, - formfield_callback=lambda f: f.formfield()): + def __new__(cls, name, bases, attrs): + formfield_callback = attrs.pop('formfield_callback', + lambda f: f.formfield()) try: parents = [b for b in bases if issubclass(b, ModelForm)] except NameError: # We are defining ModelForm itself. parents = None + new_class = super(ModelFormMetaclass, cls).__new__(cls, name, bases, + attrs) if not parents: - return super(ModelFormMetaclass, cls).__new__(cls, name, bases, - attrs) + return new_class - new_class = type.__new__(cls, name, bases, attrs) declared_fields = get_declared_fields(bases, attrs, False) opts = new_class._meta = ModelFormOptions(getattr(new_class, 'Meta', None)) if opts.model: