Lets say we have House and Room models.
Each house has several rooms and each room has a number of beds.
How to select number of bedrooms in each house? All houses must appear in the result.
Model classes:
class House(models.Model):
pass
class Room(models.Model):
house = models.ForeignKey('House')
beds = models.IntegerField()
I tried:
House.objects.filter(room__beds__gt=0).annotate(bedrooms=Count('room'))
But this solution does not contain houses without bedrooms.
I prefer not to use pure SQL.