I assumed the OP wanted to get *all* instances of Item even if they don't 
have any liked status equals to 'L'.

The query you provided will filter out instances of Item with 
`itemlikestatus__count < 1` instead of returning an annotated value of 0.

Le mercredi 25 septembre 2013 04:41:37 UTC-4, Daniel Roseman a écrit :
>
> 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