views:

125

answers:

1

I'd like to be able to display additional information like a text label with each row in a Django formset.

Example/usecase:

User picks 5 rows in a model that would he would like some action performed. A popup appears that displays a 5 form formset some additional information (that are model instance methods) based on the 5 rows chosen previously. User does some input, submits forms and 5 new rows are created in a different model.

Currently I'm thinking about passing a dictionary of this additional information in separately and somehow associating them with each form in the formset. But to get that to work I need to be able to set unique initial data for each row so I can use a hidden field for instance (I've posted another question for that specific issue).

It would be neater if I could associate the additional information with the form in a manner that would allow me to iterate through the form on the template or call 'as_table'.

A: 

This one stumped me for a bit too. Hopefully this is what you're looking for.

{{ formset.management_form }} {% for form in formset.forms %} {{ form.id }} {{ form.FirstName }} {{ form.instance.LastName }} {% endfor %}

Aaron C. de Bruyn