【发布时间】:2013-03-02 14:23:45
【问题描述】:
Car.objects.all() # 5 cars in db, every car costs 1000 $
Car.objects.all().aggregate(Sum("price")) # result: 5000
# aggregate only on a subset
Car.objects.all()[3:].aggregate(Sum("price")) # result: 5000!, not 3000
# with filter()[3:] i got the same results!
为什么?分片不在 db 中求值?
我如何使用聚合来实现?
【问题讨论】:
标签: python django aggregate slice django-queryset