2

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() )

1 Answer 1

4

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.