Skip to content Skip to sidebar Skip to footer

Same Row Multiple Times In A Form In Django

have a form by which user can enter details about some expenses but i want to have same row in the form again and again but couldn't find out how to do that : if you see figure ab

Solution 1:

For that use Formeset function, Here is the idea for print form in multiple times

ExpenditureFormSet = formset_factory(ExpenditureForm, extra=3,)

And views like

if formset.is_valid():
            fordatain formset.cleaned_data:

And pass it into {formset} So html will print the extra 3 forms

Solution 2:

You should use ModelFormSets instead of ModelForm. And if you're going to add forms dynamically, use corresponding JavaScript plugin (since management form should be changed every time new form is added).

Post a Comment for "Same Row Multiple Times In A Form In Django"