Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Form prefix vs. Form set

Tags:

python

django

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

  • Form prefix
  • Form sets

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.

like image 649
Iodnas Avatar asked Oct 29 '25 16:10

Iodnas


1 Answers

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.

like image 64
jpic Avatar answered Nov 01 '25 07:11

jpic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!