Ticket #12915: formfield_callback_inheritance_v2.diff
File formfield_callback_inheritance_v2.diff, 1.1 KB (added by , 15 years ago) |
---|
-
django/forms/models.py
179 179 180 180 class ModelFormMetaclass(type): 181 181 def __new__(cls, name, bases, attrs): 182 formfield_callback = attrs.pop('formfield_callback',183 lambda f: f.formfield())182 if 'formfield_callback' in attrs: 183 attrs['formfield_callback'] = staticmethod(attrs['formfield_callback']) 184 184 try: 185 185 parents = [b for b in bases if issubclass(b, ModelForm)] 186 186 except NameError: … … 198 198 if opts.model: 199 199 # If a model is defined, extract form fields from it. 200 200 fields = fields_for_model(opts.model, opts.fields, 201 opts.exclude, formfield_callback)201 opts.exclude, getattr(new_class, 'formfield_callback', lambda f: f.formfield())) 202 202 # Override default model fields with any custom declared ones 203 203 # (plus, include all the other declared fields). 204 204 fields.update(declared_fields)