【发布时间】:2019-12-10 06:45:56
【问题描述】:
我有这些字段(test_type, status, begin_time, and_time)。status 字段具有三种状态(0、1 或 2)。
我想在哪里做一个查询集:
(test_type = 'difficult') and
(if status=1 and begin_time + 2x(end_time - begin_time) < timezone.now()) or
(if status=2 and end_time < timezone.now())
然后选择这些字段。如果状态 state=0 我不想选择该字段。 如何使用 Django ORM 制作这个查询集?
【问题讨论】:
-
status==1 和 status==2 返回 False。 test_type = 'difficult') 没有打开的括号和 = 而不是 ==。你能检查一下你的表情吗?
-
我已将 And 改正为 OR
-
你能分享你的模型吗?
标签: python django django-queryset