class django.views.generic.edit.ModelFormMixin
A form mixin that works on ModelForms, rather than a standalone form.
Since this is a subclass of SingleObjectMixin, instances of this mixin have access to the model and queryset attributes, describing the type of object that the ModelForm is manipulating.
If you specify both the fields and form_class attributes, an ImproperlyConfigured exception will be raised.
Mixins
django.views.generic.edit.FormMixindjango.views.generic.detail.SingleObjectMixin
Methods and Attributes
-
model -
A model class. Can be explicitly provided, otherwise will be determined by examining
self.objectorqueryset.
-
fields -
A list of names of fields. This is interpreted the same way as the
Meta.fieldsattribute ofModelForm.This is a required attribute if you are generating the form class automatically (e.g. using
model). Omitting this attribute will result in anImproperlyConfiguredexception.
-
success_url -
The URL to redirect to when the form is successfully processed.
success_urlmay contain dictionary string formatting, which will be interpolated against the object’s field attributes. For example, you could usesuccess_url="/polls/{slug}/"to redirect to a URL composed out of theslugfield on a model.
-
get_form_class() -
Retrieve the form class to instantiate. If
form_classis provided, that class will be used. Otherwise, aModelFormwill be instantiated using the model associated with thequeryset, or with themodel, depending on which attribute is provided.
-
get_form_kwargs() -
Add the current instance (
self.object) to the standardget_form_kwargs().
-
get_success_url() -
Determine the URL to redirect to when the form is successfully validated. Returns
django.views.generic.edit.ModelFormMixin.success_urlif it is provided; otherwise, attempts to use theget_absolute_url()of the object.
-
form_valid(form) -
Saves the form instance, sets the current object for the view, and redirects to
get_success_url().
-
form_invalid() -
Renders a response, providing the invalid form as context.
Please login to continue.