from django.forms.forms import BoundField class FieldStack(object): """ EXAMPLE: class MyForm(forms.Form): first_name = forms.CharField() last_name = forms.CharField() website = forms.CharField() twitter = forms.CharField() facebook = forms.CharField() personal_info = FieldStack('first_name', 'last_name') contact_info = FieldStack('website', 'twitter', 'facebook') {% for field in form.contact_info %} {% endfor %}
{{field.name}}{{ field }}{{field.errors}}
""" def __init__(self, *args): self.fields = args def __get__(self, form, objtype=None): for field in self.fields: yield BoundField(form, form.fields[field], field)