I am computing some statistics based on two different filters, but I'm not sure how I can combine both results into a single QuerySet.
My code looks like this:
qs1 = User.objects.filter(c1).annotate(count1=Count("id"))
qs2 = User.objects.filter(c2).annotate(count2=Count("id"))
I would like to create a third queryset, qs3
which has both count1
and count2
. Basically I want to left join on User.id
but I can't find a straightforward way of doing that.
I also tried
count1 = Count('id', filter=c1)
count2 = Count('id', filter=c2)
qs3 = User.objects.annotate(count1=count1).annotate(count2=count2)
But it gave me different results.