Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Formset vs Modelform

Tags:

python

django

web

I am a bit confused. I know that by using Formset we could generate multiple form. Aside from that , when should I use Formset or Modelform?

like image 821
Haikal Nashuha Avatar asked Dec 04 '22 18:12

Haikal Nashuha


1 Answers

ModelForms are used to automatically create forms based on a single model instance.

If you don't have a model instance (and don't want to create one), but just want to handle arbitrary data, use a plain old form.

If you have lists of data that you need to get, whether as Models or data, FormSets are the answer.

FormSets are used to automatically manage lists of forms. You don't want to handle each form separately unless you need to. A FormSet can also use ModelForms, Yeah!

like image 157
leech Avatar answered Dec 24 '22 09:12

leech