0

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()
David Pekker
  • 333
  • 3
  • 12
  • Possible duplicate of [How to query as GROUP BY in django?](https://stackoverflow.com/questions/629551/how-to-query-as-group-by-in-django) – dahrens Jan 19 '18 at 02:31

1 Answers1

1

You can try

qs.values('your_choice').annotate(dcount=Count('your_choice'))
arjunattam
  • 2,679
  • 18
  • 24