prefetch_related() works great. How about prefetching some computed value instead of records?
{% for item in items %} {{ item.name }} {{ item.score }} {% endfor %} I want to prefetch 'score' for every item, where 'score' would be equivalent to: score = Votes.objects.all().count() - Votes.objects.filter(value=False). count() Is there any way to prefetch such query? Code below prefetches all data for Vote records. How can it be changed to prefetch only the score? Item.objects.all().prefetch_related('votes') -- 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c63c09b7-0d07-464a-be96-35fd544b7545%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.