1👍
✅
As discussed in the comments, you need a formset.
def create_people(request):
PeopleFormSet = modelformset_factory(Man, form=ManForm)
if request.method == 'POST':
formset = PeopleFormSet(request.POST)
if formset.is_valid():
for form in formset:
... do something with individual form
else:
formset = PeopleFormSet()
return render(request, template_name, {'formset': formset}
0👍
For using formsets in function based views see @Daniel Roseman ‘s answer or read up here.
For class based views there is no built in generic view for this. According to this ticket they decided to let third-party-packages handle that. You can use django-extra-views for that.
- Django M2M with addititional data with through
- Django save multiple user types
- Django Form csrf_token
- Django, Django REST Framework, Internet Explorer and CSRF token missing or incorrect
- Calling super method in Django TestCase causes RecursionError
Source:stackexchange.com