I am using django\'s inline formset factory. To use the example in the docs,
author = Author.objects.get(pk=1)
BookFormSet = inlineformset_factory(Author, Book)
Actually the answer is given in the documentation. Just don't give any instance to the FormSet. From the doc:
>>> from django.forms.models import inlineformset_factory
>>> BookFormSet = inlineformset_factory(Author, Book)
>>> author = Author.objects.get(name=u'Mike Royko')
>>> formset = BookFormSet() # This will create an empty form with your model fields
You can then create view as follows:
if request.method == "POST":
formset = BookFormSet(request.POST, request.FILES)
if formset.is_valid():
formset.save()
else:
formset = BookFormSet()
return render_to_response("add_book.html", {
"formset": formset,
Hope it helps.