Pergunta

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() )
Foi útil?

Solução

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)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top