The easiest way to use model forms with class-based views is to pass in the model and save the slug / pk written in the url, in which case you will not need to write any view code.
url(r'^myurl/$', CreateView.as_view(model=mymodel))
You can also override methods to get more complex logic. You can also pass a set of queries instead of a model object.
Another way is to create modelform in forms.py and then pass form_class to url as
url(r'^myurl/$', CreateView.as_view(form_class=myform))
This method allows you to define form functions as well as meta attributes for the form.
acid_crucifix
source share