Get list of occurrences + count in a model Django?

前端 未结 1 473
-上瘾入骨i
-上瘾入骨i 2021-02-14 01:37

Imagine I have the following model:

class Person(models.Model):
    ...other stuff...
    optional_first_name= models.CharField(max_length=50, blank=True)


        
相关标签:
1条回答
  • 2021-02-14 02:02

    After some digging, finally found out:

    Person.objects.values('optional_first_name').annotate(c=Count('optional_first_name')).order_by('-c')
    
    0 讨论(0)
提交回复
热议问题