Reputation: 353
there is a model field with choices:
class MyModel(models.Model):
your_choice = models.CharField(choices=('A', 'B', 'C', 'D'))
what is the most compact way to get the most popular choice from the queryset?
If for example, the queryset is:
qs = MyModel.objects.all()
Upvotes: 0
Views: 65
Reputation: 2819
You can try
qs.values('your_choice').annotate(dcount=Count('your_choice'))
Upvotes: 1