Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 075098f9fd06c42faaba01ec8f855f4d4e99dae6 1 parent 0d0cbfd
Malcolm Tredinnick authored July 06, 2008

Showing 1 changed file with 6 additions and 5 deletions. Show diff stats Hide diff stats

  1. 11  django/newforms/models.py
11  django/newforms/models.py
@@ -213,18 +213,19 @@ def __init__(self, options=None):
213 213
 
214 214
 
215 215
 class ModelFormMetaclass(type):
216  
-    def __new__(cls, name, bases, attrs,
217  
-                formfield_callback=lambda f: f.formfield()):
  216
+    def __new__(cls, name, bases, attrs):
  217
+        formfield_callback = attrs.pop('formfield_callback',
  218
+                lambda f: f.formfield())
218 219
         try:
219 220
             parents = [b for b in bases if issubclass(b, ModelForm)]
220 221
         except NameError:
221 222
             # We are defining ModelForm itself.
222 223
             parents = None
  224
+        new_class = super(ModelFormMetaclass, cls).__new__(cls, name, bases,
  225
+                attrs)
223 226
         if not parents:
224  
-            return super(ModelFormMetaclass, cls).__new__(cls, name, bases,
225  
-                    attrs)
  227
+            return new_class
226 228
 
227  
-        new_class = type.__new__(cls, name, bases, attrs)
228 229
         declared_fields = get_declared_fields(bases, attrs, False)
229 230
         opts = new_class._meta = ModelFormOptions(getattr(new_class, 'Meta', None))
230 231
         if opts.model:

0 notes on commit 075098f

Please sign in to comment.
Something went wrong with that request. Please try again.