Dynamically alter the attributes of a formset

 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)
    

More like this

  1. Arbitrary length formset by Rupe 3 years, 8 months ago
  2. Complex Formsets, Redux by smagala 3 years, 2 months ago
  3. Form and FormSet that are defined dynamically with request-data by Lacour 3 years, 4 months ago
  4. Dynamical formsets by I159 1 year, 6 months ago
  5. Pagination/Filtering Alphabetically by zain 4 years, 2 months ago

Comments

(Forgotten your password?)