Decrease DB requests number from Django templates

Posted by Andrew on Stack Overflow See other posts from Stack Overflow or by Andrew
Published on 2010-04-14T06:04:10Z Indexed on 2010/04/14 6:23 UTC
Read the original article Hit count: 404

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?

© Stack Overflow or respective owner

Related posts about django-models

Related posts about django