- May 31, 2010
- dynamic formset attributes
- 2 (after 2 ratings)
Allow you to specify a "General case formset/modelformset" and then alter the attributes of that formset, specificly: extra, can_order, can_delete and max_num.
So you specify:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
from django.forms.formsets import formset_factory def dynamic_formset(formset, extra=None, can_order=None, can_delete=None, max_num=None): if extra is None: extra = formset.extra if can_order is None: can_order = formset.can_order if can_delete is None: can_delete = formset.can_delete if max_num is None: max_num = formset.max_num return formset_factory(form = formset.form, formset = formset.__class__, extra = extra, can_order = can_order, can_delete = can_delete, max_num = max_num)