Ticket #12915: formfield_callback_inheritance_v2.diff

File formfield_callback_inheritance_v2.diff, 1.1 KB (added by Ilya Semenov, 14 years ago)

a simplier version which leaves the inheritance/lookup logic to Python

  • django/forms/models.py

     
    179179
    180180class ModelFormMetaclass(type):
    181181    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'])
    184184        try:
    185185            parents = [b for b in bases if issubclass(b, ModelForm)]
    186186        except NameError:
     
    198198        if opts.model:
    199199            # If a model is defined, extract form fields from it.
    200200            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()))
    202202            # Override default model fields with any custom declared ones
    203203            # (plus, include all the other declared fields).
    204204            fields.update(declared_fields)
Back to Top