1 | Metadata-Version: 1.0 |
---|
2 | Name: django-multi-form-view |
---|
3 | Version: 1.0 |
---|
4 | Summary: Class based views for handling more than one form in a single view |
---|
5 | Home-page: https://github.com/TimBest/django-multi-form-view |
---|
6 | Author: Tim Best |
---|
7 | Author-email: UNKNOWN |
---|
8 | License: GNU licence, see LICENCE |
---|
9 | Description: # Django Multi. Form View |
---|
10 | [![CircleCI](https://circleci.com/gh/TimBest/django-multi-form-view.svg?style=shield)](https://circleci.com/gh/TimBest/django-multi-form-view) |
---|
11 | [![codecov](https://codecov.io/gh/timbest/django-multi-form-view/branch/master/graph/badge.svg)](https://codecov.io/gh/timbest/django-multi-form-view) |
---|
12 | [![PyPI](https://img.shields.io/pypi/v/django-multi-form-view.svg?maxAge=2592000)](https://pypi.python.org/pypi/django-multi-form-view) |
---|
13 | [![PyPI](https://img.shields.io/pypi/dm/django-multi-form-view.svg?maxAge=2592000)](https://pypi.python.org/pypi/django-multi-form-view) |
---|
14 | |
---|
15 | Django class based views for using more than one Form or ModelForm in a single view. |
---|
16 | |
---|
17 | ## Install |
---|
18 | ```bash |
---|
19 | $ pip install django-multi-form-view |
---|
20 | ``` |
---|
21 | |
---|
22 | ## Usage |
---|
23 | |
---|
24 | ### MultiFormView ([Example](demo/base/views.py)) |
---|
25 | **class multi_form_view.MultiFormView** |
---|
26 | A single view that can display multiple Django forms. Handles displaying, redisplaying on error, and |
---|
27 | redirects on form success in. |
---|
28 | |
---|
29 | #### Extends |
---|
30 | * django.views.generic import FormView |
---|
31 | |
---|
32 | #### Attributes and Methods |
---|
33 | * `form_classes` |
---|
34 | A dictionary containing to forms for the view. |
---|
35 | * `are_forms_valid()` |
---|
36 | Check if all forms defined in `form_classes` are valid. |
---|
37 | * `forms_valid()` |
---|
38 | Redirects to get_success_url(). |
---|
39 | * `forms_invalid()` |
---|
40 | Renders a response containing the form errors. |
---|
41 | * `get()` |
---|
42 | Render the forms. |
---|
43 | * `get_context_data()` |
---|
44 | Adds the results of `get_forms()` to the context dictionary with the key `'forms'`. |
---|
45 | * `get_forms()`. |
---|
46 | Initializes the forms defined in `form_classes` with initial data from `get_initial()` and kwargs |
---|
47 | from get_form_kwargs(). |
---|
48 | * `get_form_kwargs()`. |
---|
49 | Build the keyword arguments required to instantiate the form. |
---|
50 | * `get_initial()` |
---|
51 | Returns a copy of `initial` with empty initial data dictionaries for each form. |
---|
52 | * `post()` |
---|
53 | Uses `are_forms_valid()` to call either `forms_valid()` or `forms_invalid()`. |
---|
54 | |
---|
55 | ### MultiModelFormView ([Example](demo/base/views.py)) |
---|
56 | **class multi_form_view.MultiModelFormView** |
---|
57 | A single view that can display multiple Django ModelForms. Handles displaying, redisplaying on |
---|
58 | error, and redirects on form success in. |
---|
59 | |
---|
60 | #### Extends |
---|
61 | * multi_form_view.MultiFormView |
---|
62 | |
---|
63 | #### Attributes and Methods |
---|
64 | * `forms_valid()` |
---|
65 | Calls `save()` on each form. |
---|
66 | * `get_forms()`. |
---|
67 | Initializes the forms defined in `form_classes` with initial data from `get_initial()`, kwargs |
---|
68 | from get_form_kwargs() and form instance object from `get_objects()`. |
---|
69 | * `get_objects()` |
---|
70 | Returns dictionary with the instance objects for each form. Keys should match the corresponding |
---|
71 | form. |
---|
72 | |
---|
73 | ## Demo |
---|
74 | ```bash |
---|
75 | $ cd demo |
---|
76 | $ pip install -r requirements.txt |
---|
77 | $ python manage.py migrate |
---|
78 | $ python manage.py runserver |
---|
79 | ``` |
---|
80 | |
---|
81 | ## Testing |
---|
82 | Install [PhantomJS](http://phantomjs.org/) |
---|
83 | ```bash |
---|
84 | $ python demo/manage.py behave |
---|
85 | ``` |
---|
86 | |
---|
87 | Platform: UNKNOWN |
---|