开发者

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 t开发者_开发技巧his 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?


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


If the queries are all identical, it may be worth looking at johnny-cache, and see if that will improve performance.


Are you sure that django queries database? Try to use Django Debug Toolbar to see what queries django actually makes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜