django: time range based aggregate query

本秂侑毒 提交于 2019-12-03 09:02:48
Brandon Henry

it looks like according to this: http://docs.djangoproject.com/en/dev/topics/db/aggregation/#order-of-annotate-and-filter-clauses what you have should do what you want. is the documentation wrong? bug maybe?

"the second query will only include good books in the annotated count."

in regards to:

>>> Publisher.objects.filter(book__rating__gt=3.0).annotate(num_books=Count('book'))

change this to your query (forget about the order for now):

Art.objects.filter(
    artscore__date__range=(weekago, today)
).annotate(
    score=Sum('artscore__amount')
)

now we can say

"the query will only include artscores in the date range in the annotated sum."

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!