其中condition基于django中的另一个字段值



我有一个具有以下结构的表:

==========================================
itemName minPrice maxPrice curPrice
========================================== 
   A         10      20        8 
   B         15      25        12
   c         20      30        25

在mysql中就像

select * from Items where curPrice<minPrice

但我想要django,它应该像"A,B项目名称结果"一样返回。

我已经试过滤镜了,但没能成功。

要将过滤器中的值与模型上的另一个字段进行比较,请使用F()对象:

from django.db.models import F
Item.objects.filter(curPrice__lt=F('minprice'))

相关内容

最新更新