In Django, how do you create a set of forms manually in a template?

I build the pieces of the form set manually in the template. How to get hidden fields TOTAL_FORMS and INITIAL_FORMS. Is there a hidden widget with them in it already there that I can call?

<label>formset title</label>
#formset.TOTAL_FORMS
#formset.INITIAL_FORMS
{% for form in formset.forms %}
    {{form.field}}
    {{form.id}}
{% endfor %}
+3
source share
2 answers

You can also shorten this by simply displaying a control form consisting of two hidden fields:

{{ formset.management_form }}

I did not correctly quote this information, which can be found at: http://docs.djangoproject.com/en/dev/topics/forms/formsets/

+10
source

Fumbling in the internal details, I found the answer to my question:

{{formset.management_form.TOTAL_FORMS}}
{{formset.management_form.INITIAL_FORMS}}
0
source

Source: https://habr.com/ru/post/1713265/


All Articles