[Django]-Query for top x elements in Django

59👍

Employer.objects.values('id').annotate(jobtitle_count=Count('jobtitle')).order_by('-jobtitle_count')[:5]

11👍

from django.db.models import Count

Employer.objects.annotate(Count('jobtitle')).order_by('-jobtitle__count')[:5]
👤Jj.

Leave a comment