Django Formset without instance

In this Django, Doc explains how to create a set of forms that allows you to edit books owned by a specific author.

What I want to do: Create a set of forms that will allow you to add a new book belonging to a NEW author ... Add a book and their authors to the same set of forms.

Can you freshen up? thanks.

+6
python django forms inline-formset formset
source share
2 answers

When you create a form and a set of forms for the initial display, you do not need to provide an instance - so you just get empty forms.

When you submit the data to POST, you can first make the form, save it and get an instance. You can then pass this instance to the form set so that it correctly stores related objects.

+8
source share

It depends on whether you are doing this yourself or using the built-in administrator.

If you are using an administrator, you can use inlines .

If you do this in your own application, then it is up to you. Create a single form with fields for the new author and book . When a user submits a form, your job is to create new entries.

0
source share

All Articles