【发布时间】:2014-02-03 04:14:48
【问题描述】:
我正在使用烧瓶框架和 mongoengine 为餐厅建立一个预订网站。
我的主要目标是使用 json 获取客户 ID 等于所需客户 ID 的所有预订对象
data = rzv.objects(restaurant=rest, customer=cdb.objects.get(id=request.args.get("customer-reservation"))).all()
当我尝试触发这个查询时,json 给了我一个错误:
mongoengine.errors.InvalidQueryError
我的预订模式如下:
class Reservations(document.Document):
restaurant = fields.ReferenceField(Restaurant)
customer = fields.ReferenceField(Customers)
shift_type = fields.EmbeddedDocumentField(Shifts)
room = fields.ReferenceField(Rooms)
time = fields.StringField()
covers = fields.IntField()
status = fields.StringField(default="wait")
desk = fields.EmbeddedDocumentField(Desks)
date = fields.DateTimeField()
sit_date = fields.DateTimeField()
end_sit_date = fields.DateTimeField()
cancel_date = fields.DateTimeField()
我的客户模型如下:
class Customers(document.Document):
title = fields.StringField()
full_name = fields.StringField()
first_name = fields.StringField()
last_name = fields.StringField()
telephone = fields.StringField()
visits = fields.StringField()
json:
$.getJSON("?customer-reservation=" + $(this).attr("data-id"), function (data) {
console.log(data);
reservationFill(data);
});
最后是视图:
if request.args.get("customer-reservation"):
data = rzv.objects(restaurant=rest, customer=cdb.objects.get(id=request.args.get("customer-reservation"))).all()
return data
查询这种情况的正确方法是什么。我必须使用过滤器吗?
【问题讨论】:
标签: python json mongodb mongoengine