[Answered ]-Django conditional aggregation

2👍

Alright, I guess I didn’t think this through very far. I didn’t realize that filter handled things with a left join (though thinking on it, how else would it map to the db?), so the obvious answer is:

Employee.objects.filter(type='salesman').filter(sale__timestamp__gte = start_date)\
        .exclude(sale__timestamp__gte = end_date).annotate(...

Leave a comment