Anonymous committed 7bba655

Fixed #7289 -- Made ModelForms behave like Forms in the sense that Field
objects don't appear as attributes on the final form instance. They continue to
appear as elements of the form_instance.fields mapping.

If you were relying on ModelForms having fields as attributes, then this will
be slightly backwards incompatible. However, normal template usage will see no
change at all.

Patch from Daniel Pope.

Comments (0)

Files changed (1)


         except NameError:
             # We are defining ModelForm itself.
             parents = None
+        declared_fields = get_declared_fields(bases, attrs, False)
         new_class = super(ModelFormMetaclass, cls).__new__(cls, name, bases,
         if not parents:
         if 'media' not in attrs:
    = media_property(new_class)
-        declared_fields = get_declared_fields(bases, attrs, False)
         opts = new_class._meta = ModelFormOptions(getattr(new_class, 'Meta', None))
         if opts.model:
             # If a model is defined, extract form fields from it.