views:

284

answers:

2

I am constructing the pieces of a formset manually in a template. How do I get the hidden fields TOTAL_FORMS and INITIAL_FORMS. Is there a hidden display 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 %}
A: 

In poking around in the internals I found the answer to my own question:

{{formset.management_form.TOTAL_FORMS}}
{{formset.management_form.INITIAL_FORMS}}
Jason Christa
+2  A: 

You can also shortcut that by just outputting the management form, which consists of those two hidden fields:

{{ formset.management_form }}

I didn't properly cite this info, which can be found at: http://docs.djangoproject.com/en/dev/topics/forms/formsets/

shawnr
Do I suck at google? Where did you find that information?
Jason Christa
It's on the main Django docs page for Formsets: http://docs.djangoproject.com/en/dev/topics/forms/formsets/But it's sort of deep at the bottom of the page and mentioned briefly.
shawnr
I find it most useful just navigate django documentation from it's main page http://docs.djangoproject.com/en/dev/ i often find what i need faster this way.
Evgeny