Ticket #12915: formfield_callback_inheritance.diff
File formfield_callback_inheritance.diff, 1.7 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 formfield_callback = attrs.pop('formfield_callback', None) 184 183 try: 185 184 parents = [b for b in bases if issubclass(b, ModelForm)] 186 185 except NameError: … … 192 191 if not parents: 193 192 return new_class 194 193 194 # If formfield_callback is not present in the class definition, 195 # copy it from the parent class. 196 if not formfield_callback: 197 for parent in parents: 198 formfield_callback = getattr(parent, 'formfield_callback', None) 199 if formfield_callback: 200 break 201 if formfield_callback: 202 new_class.formfield_callback = staticmethod(formfield_callback) 203 195 204 if 'media' not in attrs: 196 205 new_class.media = media_property(new_class) 197 206 opts = new_class._meta = ModelFormOptions(getattr(new_class, 'Meta', None)) 198 207 if opts.model: 199 208 # If a model is defined, extract form fields from it. 200 209 fields = fields_for_model(opts.model, opts.fields, 201 opts.exclude, formfield_callback )210 opts.exclude, formfield_callback or (lambda f: f.formfield())) 202 211 # Override default model fields with any custom declared ones 203 212 # (plus, include all the other declared fields). 204 213 fields.update(declared_fields)