django-formfieldset is a Django application that allows you define and render your forms with fieldsets. Just like in admin. To enable fieldset rendering you need to add FieldsetMixin as a parent class to your form and define a fieldsets attribute:
from django import forms from formfieldset.forms import FieldsetMixin class MyForm(forms.Form, FieldsetMixin): # Fields etc... fieldsets = ((u'Fieldset Title', {'fields': ('foo', 'bar', 'baz'), 'description': u'This is the description for fieldset.'}), (None, {'fields': ('some_field',), 'description': u'This fieldset has no title.'}), (u'Fieldset With No Description', {'fields': ('some_other_field',)}))
Then you can render your form with fieldset enabled methods:
<form method="POST" action=""><table>{{ form.as_fieldset_table }}</table></form>
It is far from complete1, but feel free to download and play with it.
1: Not released yet.
Related posts:
- django-renderformplain
- Dynamic Translation Apps for Django
- Developing Reusable Django Apps
- Django Fixtures
- Django: Where Should My App Live
Tags: django, forms, free software, open source, python, share