2👍
✅
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
Source:stackexchange.com