Re: Aggregation / annotation over results of a subquery

2016-05-23 Thread Malcolm Box
Thanks Simon, that's exactly what I needed. I had read the aggregation documentation, but hadn't figured out how to get it to do what I needed. Cheers, Malcolm On Friday, 20 May 2016 16:52:01 UTC+1, Simon Charette wrote: > > Hi Malcom, > > I suggest you look into the conditionnal aggregation do

Re: Aggregation / annotation over results of a subquery

2016-05-20 Thread Simon Charette
Hi Malcom, I suggest you look into the conditionnal aggregation documentation[1]. from django.db.models import Case, Count, When Contact.objects.annotate( messages_count=Count( Case(When( messages__recipient=recipient, messages__status=Message.STATUS_UNREAD,