date and integer addition in django F object
I am trying retrieve objects with the following model
Tools:
last_calibration_date: Date
period:Integer
.
.
Now to get all expired tools, I want to perform a query which does something like last_calibration_date + period < current_date
How can t开发者_高级运维his be done using django ORM? Its easy with raw query. I am trying something like
.filter(last_calibration_date__gte = date.today()+ timedelta(F('calibration_period')*30))
Not working! Is it possible?
No, F
objects don't work that way. You need to use extra()
- for instance, using MySQL:
.extra(where=['period + last_calibration_date < CURDATE()']
精彩评论