【问题标题】:How to filter using gte of a attribute of corresponding model object in django如何在 django 中使用相应模型对象的属性的 gte 进行过滤
【发布时间】:2020-12-08 00:52:29
【问题描述】:
  bar_1 = models.IntegerField()
  bar_2 = models.IntegerField()
  1. 过滤所有值 bar_1

【问题讨论】:

标签: python django database model


【解决方案1】:

您可以使用F-object [Django-doc] 进行过滤:

from django.db.models import F

MyModel.objects.filter(bar_1__lte=F('bar_2'))

使用F-object 来引用一个字段。所以F('bar_2') 代表bar_2 字段。

【讨论】:

    猜你喜欢
    • 2020-12-21
    • 2012-05-16
    • 1970-01-01
    • 1970-01-01
    • 2021-09-04
    • 1970-01-01
    • 2018-08-09
    • 2021-08-09
    • 2019-08-31
    相关资源
    最近更新 更多