5👍
✅
from django.db.models import Count
Type.objects.annotate(component_count=Count('component')).exclude(component_count=0)
Source:stackexchange.com