On 30/04/07, Mario Graziosi <[EMAIL PROTECTED]> wrote:
>
> I have a form with several checkboxes created dynamically, where each
> field has a name similar to "mycheck_xxx". From within the template I
> don't know how many checks the form holds, since these are built
> dynamically. How can I render them using the Django template system?
>
> For example, this is my Form (using newforms):
>
> class FormList(forms.Form):
>     def __init__(self, queues, *args, **kwargs):
>         super(FormList, self).__init__(*args, **kwargs)
>         # Create several check boxes
>         for n in range(5):
>             fieldname = 'mycheck_%d' % n
>             self.fields[fieldname] = forms.BooleanField(required=False)
>
> This is the template (one of several tries). Obviously, it doesn't work,
> but it reflects what I'd like to get on my form:
>
> {% for fieldname in form.fields.keys %}
>     <p>{{ form.fieldname }}</p>
> {% endfor %}
>
> Does any one know how I might accomplish this?

The following template would work with the view code you posted.

{% for field in form %}
   <p>{{ field.label }} {{ field }}</p>
{% endfor %}

-- 
Phil

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to