Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Django formset without multiple queries

I need to display multiple forms (up to 10) of a model on a page. This is the code I use for to accomplish this.

TheFormSet = formset_factory(SomeForm, extra=10)
...
formset = TheFormSet(prefix='party')

return render_to_response('template.html', {
        'formset' : formset,
})

The problem is, that it seems to me that Django queries the database for each of the forms in the formset, even though the data displayed in them is the same.

Is this the way Formsets work or am I doing something wrong? Is there a way around it inside django or would I have to use JavaScript for a workaround?

like image 267
Martin Avatar asked Nov 06 '22 13:11

Martin


1 Answers

What happens if you use modelformset_factory instead of formset_factory? Does that help?

like image 76
Daniel Roseman Avatar answered Nov 11 '22 04:11

Daniel Roseman