Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between initial and instance in django formset?

What is the difference between initial and instance in django formset?

When to use which?

What should I use to show the prepopulated data in an invalid form in the following case:

formset= FormSet(initial=[{'a':list.b} for list in listslist])
if request.method =='post':
    formset = FormSet(request.post, ---instance/initial? ---)
like image 575
Ardine Avatar asked Oct 31 '22 21:10

Ardine


1 Answers

initial is to set defaults for new forms.

instances is to set models instances you use as initial models, which will be populated with entered data. You can use this attribute to edit your model instances.

like image 140
dt0xff Avatar answered Nov 15 '22 04:11

dt0xff