On Tuesday, 24 September 2013 21:58:44 UTC+1, Simon Charette wrote:

> Unfortunately the Django ORM's doesn't support conditionnal 
> aggregates<https://code.djangoproject.com/ticket/11305>
> .
>
 
This is true, but completely irrelevant to the OP's question, which doesn't 
require them. The documentation gives an example which AFAICT is exactly 
what the OP wants, 
at 
https://docs.djangoproject.com/en/1.5/topics/db/aggregation/#order-of-annotate-and-filter-clauses.
 
Translating it into the relevant models:

items_by_popularity = 
Item.objects.all().filter(itemlikestatus__liked_status='L').annotate(Count('itemlikestatus')).order_by('-itemlikestatus__count')[:number_requested]

--
DR.

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to