【发布时间】:2016-06-10 15:41:44
【问题描述】:
我正在尝试按计算字段进行过滤,其中计算取决于其他字段的值。
我正在尝试按sales_price(计算字段)进行过滤,其中sales_price 的定义如下伪代码
if discount is NULL
sales_price = price
else
sales_price = price - price*discount/100
最终目标是按范围过滤sales_price:
filter(sales_price__range=(price_min, price_max))
这是我的模型:
class Product(models.Model):
price = models.IntegerField()
discount = models.IntegerField(blank=True, null=True)
【问题讨论】:
-
您是否将 GET 参数转换为整数?
-
price1 是否低于 price2?
-
是的,它低于 price2
-
我在上面转换为 int 检查
-
如何查询该范围内的sales_price
标签: python django django-orm