I have two models:
class Unit (models.Model): Unit_name = models.CharField(max_length=30) Hull_number = models.CharField(max_length=30) Parent_unit =
Hope this helps:
from django.db.models import Count MemberUnit.objects.values('Unit__Unit_name').annotate(c=Count('Unit'))
You can try this in Django's shell:
manage.py shell
See docs