Django使用字段值查找过滤查询集

时间:2015-02-06 20:31:15

标签: python django

我的模型有2个十进制字段

class Order (models.Model):    
    ordered = models.DecimalField(...)
    received = models.DecimalField(...)

我需要检索received小于ordered的行。

类似的东西:

SELECT * from Order WHERE received < ordered

是否有django语法方式?

1 个答案:

答案 0 :(得分:2)

>>> from django.db.models import F
>>> Order.objects.filter(received__lt=F('ordered'))