I have the following models:
Family():
family_id = models.CharField(db_index=True, max_length=100)
Individual():
individual_id = models.TextField(db_index=True)
family = models.ForeignKey(Family, on_delete=models.PROTECT)
I need to write a query to get the following result:
Family Count | Individual Count 1 | 3 5 | 8 10 | 19
So, I need to categorize families (not as their family_ids, but as their counts!) by the number of individuals they have. Is it possible? And if yes, how?
So far I am able to get how many individuals each family_id has:
overview_data = Family.objects.annotate(ind_count=Count('individual')).order_by('ind_count')
Now I need a way to sum them up by the number of individuals their groups have.