【发布时间】:2021-11-25 02:25:02
【问题描述】:
我有以下数据:
publisher title
-------------------------- -----------------------------------
New Age Books Life Without Fear
New Age Books Life Without Fear
New Age Books Sushi, Anyone?
Binnet & Hardley Life Without Fear
Binnet & Hardley The Gourmet Microwave
Binnet & Hardley Silicon Valley
Algodata Infosystems But Is It User Friendly?
Algodata Infosystems But Is It User Friendly?
Algodata Infosystems But Is It User Friendly?
这就是我想做的事情:我想计算单个对象中每个作者出版的书籍数量。 我想得到以下结果:
{publisher: New Age Books, titles: {Life Without Fear: 2, Sushi Anyone?: 1}},
{publisher: Binnet & Hardley, titles: {The Gourmet Microwave: 1, Silicon Valley: 1, Life Without Fear: 1}},
{publisher: Algodata Infosystems, titles: {But Is It User Friendly?: 3}}
我的解决方案大致如下:
query_set.values('publisher', 'title').annotate(count=Count('title'))
但它没有产生预期的结果。
【问题讨论】:
标签: django database django-models django-rest-framework orm