Django class based views for using more than one Form or ModelForm in a single view.
$ pip install django-multi-form-viewMultiFormView (Example)
class multi_form_view.MultiFormView A single view that can display multiple Django forms. Handles displaying, redisplaying on error, and redirects on form success in.
- django.views.generic import FormView
form_classesA dictionary containing to forms for the view.are_forms_valid()Check if all forms defined inform_classesare valid.forms_valid()Redirects to get_success_url().forms_invalid()Renders a response containing the form errors.get()Render the forms.get_context_data()Adds the results ofget_forms()to the context dictionary with the key'forms'.get_forms(). Initializes the forms defined inform_classeswith initial data fromget_initial()and kwargs from get_form_kwargs().get_form_kwargs(). Build the keyword arguments required to instantiate the form.get_initial()Returns a copy ofinitialwith empty initial data dictionaries for each form.post()Usesare_forms_valid()to call eitherforms_valid()orforms_invalid().
MultiModelFormView (Example)
class multi_form_view.MultiModelFormView A single view that can display multiple Django ModelForms. Handles displaying, redisplaying on error, and redirects on form success in.
- multi_form_view.MultiFormView
forms_valid()Callssave()on each form.get_forms(). Initializes the forms defined inform_classeswith initial data fromget_initial(), kwargs from get_form_kwargs() and form instance object fromget_objects().get_objects()Returns dictionary with the instance objects for each form. Keys should match the corresponding form.
$ cd demo
$ pip3 install -r requirements.txt
$ python3 manage.py migrate
$ python3 manage.py runserverInstall headless chrome
$ python3 demo/manage.py behave