Ticket #7617: models.diff

File models.diff, 1.7 KB (added by Christian Tanzer <tanzer@…>, 7 years ago)

patch for newforms/models.py

  • django/newforms/models.py

     
    215215
    216216
    217217class ModelFormMetaclass(type):
    218     def __new__(cls, name, bases, attrs,
    219                 formfield_callback=lambda f: f.formfield()):
     218    def __new__(cls, name, bases, attrs):
     219        formfield_callback = attrs.pop('formfield_callback',
     220                                       lambda f: f.formfield())
    220221        try:
    221222            parents = [b for b in bases if issubclass(b, ModelForm)]
    222223        except NameError:
    223224            # We are defining ModelForm itself.
    224225            parents = None
     226        new_class = super(ModelFormMetaclass, cls).__new__(cls, name, bases,
     227                    attrs)
    225228        if not parents:
    226             return super(ModelFormMetaclass, cls).__new__(cls, name, bases,
    227                     attrs)
    228 
    229         new_class = type.__new__(cls, name, bases, attrs)
     229            return new_class
    230230        if 'media' not in attrs:
    231231            new_class.media = media_property(new_class)
    232232        declared_fields = get_declared_fields(bases, attrs, False)
     
    289289    setattr(Meta, 'fields', fields)
    290290    setattr(Meta, 'exclude', exclude)
    291291    class_name = model.__name__ + 'Form'
    292     return ModelFormMetaclass(class_name, (form,), {'Meta': Meta},
    293                               formfield_callback=formfield_callback)
     292    return ModelFormMetaclass(class_name, (form,),
     293                              {'Meta': Meta,
     294                               'formfield_callback': formfield_callback})
    294295
    295296
    296297# ModelFormSets ##############################################################
Back to Top