Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use multiple number of formset in a single form in django,if yes how?

I have to make a form in which more than one formset is used. please tell me if this is possible. if yes then how?

like image 353
nimeshkiranverma Avatar asked Jul 04 '12 07:07

nimeshkiranverma


1 Answers

You can add as many formsets in the form. Just create/init them in view and pass to template to render in the form.

Something like:

{{ formset1.management_form }}
{% for form in formset1 %}
    {{ form }}
{% endfor %}

{{ formset2.management_form }}
{% for form in formset2 %}
    {{ form }}
{% endfor %}

You are using multiple formsets in one view, you need to use prefix for the forms as explained here Using more than one formset in a view In short:

article_formset = ArticleFormSet(prefix='articles')
book_formset = BookFormSet(prefix='books')
like image 108
Rohan Avatar answered Sep 30 '22 20:09

Rohan