Re: Efficient way to perform many queries

2014-08-17 Thread 9devmail
Thank you, it works perfectly :) -- 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

Re: Efficient way to perform many queries

2014-08-16 Thread Collin Anderson
I think this should work: Item.objects.exclude(votes__value=False).annotate(score=Count('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+u

Re: Efficient way to perform many queries

2014-08-16 Thread 9devmail
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() -

Re: Efficient way to perform many queries

2014-08-15 Thread Sergiy Khohlov
good question ! 1) I like to use some optimization at view side not template 2) if i need something like your code I using optimization. Something like that : {% with items = mymodels.items.all %} {% for item in items %} {{ item.name }} {% for tag in item.tags.all %} {{ tag }

Re: Efficient way to perform many queries

2014-08-15 Thread 9devmail
Thank you. What if I'm using GenericForeignKey in Tags model? Can I still use it? -- 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...@googl

Re: Efficient way to perform many queries

2014-08-15 Thread Collin Anderson
you could try in your view: items = items.prefetch_related('tags') -- 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. T

Efficient way to perform many queries

2014-08-15 Thread 9devmail
I am writing application similar to django-taggit and I was wondering about its performance. Example for list of items: {% for item in items %} {{ item.name }} {% for tag in item.tags.all %} {{ tag }} {% endfor %} {% endfor %} Abov