我有一个关于
django注释方法的问题:
是否可以计算这3个特定折扣的“maximum_discount”(并按此“maximum_discount”排序)?
Product.objects\
.annotate(
product_discount=Max('discounts__amount'),
category_discount=Max('category__discounts__amount'),
brand_discount=Max('brand__discounts__amount')
)
最佳答案 尝试这样的事情:
max_discount = max(value for key, value in Product.objects\
.annotate( # maybe 'aggregate'?
product_discount=Max('discounts__amount'),
category_discount=Max('category__discounts__amount'),
brand_discount=Max('brand__discounts__amount')
)
)