我有一个带有几个注释的查询集,包括两个字段:price
和price_after_discount
.我想实现一个基于特定值的max_Filter.但是,我需要处理一个条件:如果price_after_discount
字段不等于0,则应该对该字段应用过滤器;否则,应该对price
字段应用过滤器.
我try 了以下代码,尽管它不能正常运行.这是一个示例代码:
value = 200
queryset.filter(
Case(
When(price_after_discount=0, then=F("price")),
default=F("price_after_discount")
)__lt=value
)
您能提供关于如何基于price_after_discount
和price
字段正确实现max_Filter条件的指导吗?