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

html - How to custom Bootstrap grid height? -

javascript - pass values from mssql to views in node -

image - python get coordinates (pixels) of corresponding points from clicks -