Iodnas
Iodnas

Reputation: 3504

Django Form prefix vs. Form set

There exist two ways in Django to process the several forms in one request:

In which use case is each one preferable?

In my specific case, the form lists the fields for an object to be updated from a diff. For each field, an action can be defined (like "update value", "keep value"). The page contains forms for several objects.

Upvotes: 4

Views: 2861

Answers (1)

jpic
jpic

Reputation: 33420

If you have several different forms classes with same input names, like a PetForm and an OwnerForm with both a name input in the same page, then you have to use a prefix as explained in the documentation you linked.

If you want to have the same form class repeated, ie. to render a table of TicketForm, then you can use Formsets directly: Formsets use the form prefix feature internally and you don't have to worry about it.

Upvotes: 9

Related Questions