Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Formset without instance

In this Django Doc explain how to create a formset that allows you to edit books belonging to a particular author.

What I want to do is: Create a formset that allows you to ADD new book belonging to a NEW author... Add the Book and their Authors in the same formset.

Can you gime a light? thanks.

like image 586
panchicore Avatar asked Aug 12 '09 18:08

panchicore


1 Answers

When you're instantiating the form and formset for the initial display, you don't need to provide an instance - so you will just get blank forms.

When you pass in the data on POST, you can do the form first, save it, and get an instance. Then you can pass that instance into the formset, so that it correctly saves the related objects.

like image 70
Daniel Roseman Avatar answered Oct 13 '22 22:10

Daniel Roseman