[Django]-Increasing number of initial forms in a Django formset based on data in POST?

0👍

It turns out that the solution is to use the formset’s management form to modify the actual request data:

from django.forms.formsets import INITIAL_FORM_COUNT
if formset.initial_form_count() < formset.total_form_count():
    manform = formset.management_form
    prefixed_name = manform.add_prefix(INITIAL_FORM_COUNT)
    manform.data[prefixed_name] = formset.total_form_count()
👤Marcin

Leave a comment