【发布时间】:2026-02-06 14:10:01
【问题描述】:
这就是我的模型的样子。 A 类的 EmbeddedDocumentListField 为 SlotTime。
class SlotTime(EmbeddedDocument):
# this is having minutes like 780 for 1pm.
start_time = IntField(required=True)
end_time = IntField(required=True)
class A(Document):
name = StringField(primary_key=True)
slot_hours = EmbeddedDocumentListField(SlotTime)
SlotTime 有一个包含开始和结束时间值的对象列表。
[<SlotTime: SlotTime object>,<SlotTime: SlotTime object>]
现在我想进行一个查询,它将返回 start_time 大于给定值的结果。
想要一个类似于这个查询的东西:A.objects.get(name__exact='xyz').slot_hours.filter(start_time__gte=780)
试过了,但这会返回所有值。 A.objects.filter(name__exact='xyz',slot_hours__start_time__gte=780)[0].slot_hours
有人可以帮助我如何做到这一点吗?谢谢!
【问题讨论】:
-
请添加
OrderTime的代码。 -
编辑了代码。 @RahulGupta
标签: django python-2.7 mongoengine