gpt4 book ai didi

python - django 聚合后的结果是什么?

转载 作者:行者123 更新时间:2023-12-01 03:40:03 24 4
gpt4 key购买 nike

我在 django 项目中看到以下代码。我理解它是聚合,但是聚合后的 ['kw__sum'] 是什么?

Project.objects.filter(project = project).aggregate(Sum('kw'))['kw__sum']

谢谢

最佳答案

如果你查看 examples 就在这里你会看到aggregate返回字典,所以最后一部分只是字典查找

aggregation = Project.objects.filter(project = project).aggregate(Sum('kw'))
result = aggregation['kw__sum']

来自文档

Returns a dictionary of aggregate values (averages, sums, etc.) calculated over the QuerySet. Each argument to aggregate() specifies a value that will be included in the dictionary that is returned.

关于python - django 聚合后的结果是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39738438/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com