Hello. When using django’s generic class based views (Create and Update View), does the form have to be of type ModelForm
?
Or can it be another form like forms.Form
. If so, then how would it work? What methods would I have to create, and what things would be different from using a ModelForm
? Thanks.
You can see this in the inheritance chain for the view: https://docs.djangoproject.com/en/3.0/ref/class-based-views/generic-editing/#django.views.generic.edit.CreateView
It inherits from ModelFormMixin
, so it’s intended to work with model forms only.
That said, I think you can probably duck type and use anyøa form with a .save()
method, though I haven’t tested that.
If you check the extensions to Form
that ModelForm
, and read the source code to ModelFormMixin
, you’ll be able to answer this better for yourself.