这是型号:
class Work(models.Model):
start_date = DateTimeField()
end_date = DateTimeField()
sot = IntegerField(help_text='days')
我想从结束时间中减去开始时间,得到与sot比较的天数,并过滤掉我想要的数据。
我可以通过循环得到我想要的,但这是非常不雅观的,有没有办法通过ORM来做到这一点?
[w for w in Work.objects.all() if (w.end_date - w.start_date).days < w.sot ]
你可以使用F expiression
F
引用字段end_date
和start_date
end_date
中减去start_date
,这会产生以微秒为单位的时间戳差异。你知道吗sot
字段过滤日差相关问题 更多 >
编程相关推荐