I am annotating my queryset in Django, using values from another table mapping as so.
lw_list = lw_list.annotate(count_mapping=Count('mapping'))
(lw objects have a one to many relationship with the mapping objects)
So now each object in my lw list has a count of related mapping objects.
My mapping objects have a boolean field ‘pass_fail’
Is it possible to put a where clause on the mapping table, so that the aggreagte only counts mapping objects that have a “pass_fail” value set to true?
How do you do this?
I don’t think this can be done using Django’s ORM as of now — here’s a pretty active ticket about what you want, and here’s a pretty hackish workaround suggested by someone in there. I’d say your best bet would be to use raw SQL for now.