【发布时间】:2016-10-06 14:32:49
【问题描述】:
我想在注释查询集中添加比较操作来计算特定字段的值。我怎样才能做到这一点? 这是我的注释查询集
sale_item_list = OrderItem.objects.filter(order_id=order.id) \
.values('item__name') \
.annotate(price=F('price')) \
.annotate(exchange_rate=F('exchange_rate')) \
.annotate(quantity=F('quantity') \
.annotate(amount=Case(
When(F('quantity') < F('inventory'), then=Sum(F('quantity') * F('price'))),
When(F('quantity') > F('inventory'), then=Sum(F('inventory') * F('price'))),
output_field=IntegerField()))
上面我的查询集的条件表达式运行错误。请帮我解决一下?
【问题讨论】:
标签: python django python-3.x