from django.forms.forms import BoundField class FieldStackLazy(object): def __init__(self, form, *fields, **attrs): self.form, self.fields = form, fields self.__dict__.update(attrs) def __iter__(self): for field in self.fields: yield BoundField(self.form, self.form.fields[field], field) class FieldStack(object): def __init__(self, *fields, **attrs): self.fields, self.attrs = fields, attrs def __get__(self, form, objtype=None): return FieldStackLazy(form, *self.fields, **self.attrs) ################################################################# # Example form 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', title='Personal info', color='red') contact_info = FieldStack('website', 'twitter', 'facebook', title='Contact info', color='green') # Example template
{{field.name}} | {{ field }} | {{field.errors}} |