[Fixed]-Render Django formset as array

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.

👤trixn

Leave a comment