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