django F对象中的日期和整数加法

时间:2011-04-18 11:58:08

标签: django django-models

我正在尝试使用以下模型检索对象

Tools:
    last_calibration_date: Date
    period:Integer
    .
    .

现在要获取所有过期的工具,我想执行类似last_calibration_date + period < current_date

的查询

如何使用django ORM完成此操作?它很容易与原始查询。我正在尝试像

这样的东西
.filter(last_calibration_date__gte = date.today()+ timedelta(F('calibration_period')*30))

不工作!有可能吗?

1 个答案:

答案 0 :(得分:1)

不,F个对象不起作用。您需要使用extra() - 例如,使用MySQL:

.extra(where=['period + last_calibration_date < CURDATE()']