MooMoo
MooMoo

Reputation: 1116

Django create empty formset with fixed number of form

I would like to create an empty formset with fixed number ( more than 1) I am not sure is it possible to do it in views.py. I saw many methods using jquery to create a new form.

here is my code to create a new form, however the number of form is only one.

MyStuffSet = modelformset_factory( MyStuff )

formset =  MyStuffSet( queryset = MyStuff.objects.none() )

Upvotes: 2

Views: 979

Answers (1)

Priyank Patel
Priyank Patel

Reputation: 3535

You can use extra parameter . like :

MyStuffSet = modelformset_factory(MyStuff, extra=3)

OR Condition based :

MyStuffSet = modelformset_factory(MyStuff, extra=1 if request.POST.has_key('any_key') else 0)

Upvotes: 4

Related Questions