Django condition aggregation, count when entry exists -


what want this:

foo.objects.all().annotate(c=count(case(when(bar_set= exists,then 1)))) 

that is, count cases bar_set not empty.

 # should not counted  foo.bar_set()  >>> [] # should counted foo.bar_set()  >>> [<bar: bar object>] 

how can done?


Comments

Popular posts from this blog

Ansible warning on jinja2 braces on when -

Parsing a protocol message from Go by Java -

javascript - Replicate keyboard event with html button -