Everything is very simple. I have this form:
class add_basketForm(forms.Form): def __init__(self, selected_subunits, *args, **kwargs): self.selected_subunits = selected_subunits super(add_basketForm, self).__init__(*args, **kwargs) for subunit in self.selected_subunits: self.fields['su%d' % (subunit['unit__id'])] = forms.IntegerField()
The number of subunits is unknown. I would like to use something like this (you understand):
{% for unit in selected_subunits %} {{ form.su%s }} % (unit.unit__id) {% endfor %}
But of course this will not work. My question is, how can I refer to these form fields in the Django template language?
django dynamic templates forms
Brian
source share