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

标签 python django aggregation

我在 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/

相关文章:

python - Keras 模型到tensorflow.keras

reactjs - Docker - 提供 react 应用程序,asset-manifest.json 文件名不正确

python - 将 python 应用程序转换为 webapp 的最简单框架?

python - pandas 在不同大小的 2 个表(1 个聚合表)之间执行划分

python - 如果一行满足特定条件,则选择多索引数据框中的整个子组

python - 执行用 yaml 编写的带有变量的 python 脚本

python - 在Python中将字符串列表转换为整数,跳过屏蔽术语

python - 变更表单中的ModelChoiceField初始值

Elasticsearch,按地理距离和分数排序聚合

javascript - 在 JavaScript 中聚合对象数组