How to perform a join and aggregate count in Django

后端 未结 1 1765

I have two models:

class Unit (models.Model):
    Unit_name = models.CharField(max_length=30)
    Hull_number = models.CharField(max_length=30)
    Parent_unit =         


        
相关标签:
1条回答
  • 2021-01-25 01:15

    Hope this helps:

    from django.db.models import Count
    MemberUnit.objects.values('Unit__Unit_name').annotate(c=Count('Unit'))
    

    You can try this in Django's shell:

    manage.py shell
    

    See docs

    0 讨论(0)
提交回复
热议问题