{% for item in items %}
{{ item.name }}
{% for tag in item.tags.all %}
{{ tag }}
{% endfor %}
{% endfor %}
Is there any way to make it more efficient? I was thinking about merging these queries into one big. Thanks in advance for any tips.
items = items.prefetch_related('tags')
you could try in your view:
items = items.prefetch_related('tags')
--To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0acd3536-93e7-463a-9805-06d1b9236b63%40googlegroups.com.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
{% for item in items %}
{{ item.name }}
{{ item.score }}
{% endfor %}
score = Votes.objects.all().count() - Votes.objects.filter(value=False).count()
Item.objects.all().prefetch_related('votes')
Item.objects.exclude(votes__value=False).annotate(score=Count('Votes'))