1👍
✅
You can annotate with the number of filtered Tag
objects:
from django.db.models import Count
filtered = Post.objects.filter(
tags__in=['thoughts', 'django', 'example']
).alias(
ntags=Count('tags')
).order_by('-ntags')
Source:stackexchange.com