1👍
✅
You an order the SoundCategory
s by the number of items:
from django.db.models import Count
SoundCategory.objects.alias(nitem=Count('sound_reviews')).order_by('-nitem')
or when related to a single SoundItem
item:
from django.db.models import Count
SoundCategory.objects.filter(sound_reviews__sound=my_sound_item).alias(
nitem=Count('sound_reviews')
).order_by('-nitem')
Source:stackexchange.com