我希望在annotate queryset中添加比较操作以计算特定字段的值。我该怎么做?
这是我的annotate queryset:
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()))
我的查询集中的条件表达式运行出错了,能帮我修复一下吗?