How to know which field(category) most used

can I do this in one single query Note: order should not be changed.

products = Product.objects.filter(
    title__icontains=self.query
    ).values('id', 'is_featured', 'category_id').order_by('-is_featured', 'rank', '-created')

most_used_category = products.values('category_id') \
.annotate(category_count=Count('category_id')) \
.order_by('-category_count').first()
Вернуться на верх