for better performance I added select_related() for Category field then it runs just one Queryset.
and in my template I have:
{% for product in products %}
{{ product.category }} - {{ product }}
{% if 'oldPrice' in product.tags.names %}<span>Old price<span>{% endif %}
{% endfor %}
when I add this if statement in my template, it hits the database every time that there is an oldPrice tag. When there are 100 products, it hits database 100 times.
Is there any way like select_related() that helps me to reduce the numbers of executed SQLs?
I have a model like this:
In my view:
for better performance I added
select_related()
forCategory
field then it runs just one Queryset. and in my template I have:when I add this
if
statement in my template, it hits the database every time that there is anoldPrice
tag. When there are 100 products, it hits database 100 times. Is there any way likeselect_related()
that helps me to reduce the numbers of executed SQLs?