Decrease DB requests number from Django templates
- by Andrew
I publish discount offers for my city. Offer models are passed to template ( ~15 offers per page). Every offer has lot of items(every item has FK to it's offer), thus i have to make huge number of DB request from template.
{% for item in offer.1 %}
{{item.descr}}
{{item.start_date}}
{{item.price|floatformat}}
{%if not item.tax_included %}{%trans "Without taxes"%}{%endif%}
<a href="{{item.offer.wwwlink}}" >{%trans "Buy now!"%}</a> </div>
<div class="clear"></div>
{% endfor %}
So there are ~200-400 DB requests per page, that's abnormal i expect.
In django code it is possible to use select_related to prepopulate needed values, how can i decrease number of requests in template?