我正在尝试保存模型的实例,但我得到了
Invalid EmbeddedDocumentField item (1)
1
项目的 ID在哪里(我认为)。
模型定义为
class Graph(Document):
user = StringField(max_length=50, required=True)
title = StringField(max_length=500)
description = StringField(max_length=1000)
# field in error
graph_nodes = ListField(EmbeddedDocumentField(Graph_Node))
procedure = ListField(DictField())
created_on = DateTimeField(default=datetime.datetime.now)
def __unicode__(self):
return self.title
meta = {
'ordering': ['-created_on'],
'allow_inheritance': False,
}
class Graph_Node(EmbeddedDocument):
id = StringField(required=True, max_length=30)
button = StringField(max_length=40, required=True)
parameter = StringField(max_length=50, required=False)
values = ListField(StringField(max_length=30, required=False))
wires_out = ListField(StringField(max_length=30, required=False))
wires_in = ListField(StringField(max_length=30, required=False))
def __unicode__(self):
return self.id
meta = {
'allow_inheritance': False
}
def fill(self, args):
for k in args.keys():
if k in self.__dict__['_data'].keys():
self.__dict__['_data'][k] = args[k]
调用save()
方法如下:
Graph(user=request.user.username, title=title,
description=description, procedure=procedura,
graph_nodes=gnlist).save()
并且在 Graph 创建时抛出异常save
,而不是在创建图形时。
gnlist
是(从pydev debugger
)
list: [<Graph_Node: start>, <Graph_Node: 1>, <Graph_Node: end>]
并且gnlist[1]
似乎格式正确(如果需要,我会发布更多详细信息)
我试图跟踪查询,mongodb
但它似乎没有被分析,但是输出如下(以防帮助我从不相关的日志中清除它):
{ "ts" : ISODate("2012-10-26T18:25:07.492Z"), "op" : "query", "ns" : "analysis.system.indexes", "query" : { "expireAfterSeconds" : { "$exists" : true } }, "ntoreturn" : 0, "ntoskip" : 0, "nscanned" : 0, "keyUpdates" : 0, "numYield" : 0, "lockStats" : { "timeLockedMicros" : { "r" : NumberLong(248), "w" : NumberLong(0) }, "timeAcquiringMicros" : { "r" : NumberLong(2), "w" : NumberLong(4) } }, "nreturned" : 0, "responseLength" : 20, "millis" : 0, "client" : "0.0.0.0", "user" : "" }
{ "ts" : ISODate("2012-10-26T18:26:07.505Z"), "op" : "query", "ns" : "analysis.system.indexes", "query" : { "expireAfterSeconds" : { "$exists" : true } }, "ntoreturn" : 0, "ntoskip" : 0, "nscanned" : 0, "keyUpdates" : 0, "numYield" : 0, "lockStats" : { "timeLockedMicros" : { "r" : NumberLong(680), "w" : NumberLong(0) }, "timeAcquiringMicros" : { "r" : NumberLong(4), "w" : NumberLong(7) } }, "nreturned" : 0, "responseLength" : 20, "millis" : 0, "client" : "0.0.0.0", "user" : "" }
{ "ts" : ISODate("2012-10-26T18:26:25.803Z"), "op" : "query", "ns" : "analysis.system.profile", "query" : { }, "ntoreturn" : 0, "ntoskip" : 0, "nscanned" : 2, "keyUpdates" : 0, "numYield" : 0, "lockStats" : { "timeLockedMicros" : { "r" : NumberLong(62), "w" : NumberLong(0) }, "timeAcquiringMicros" : { "r" : NumberLong(7), "w" : NumberLong(3) } }, "nreturned" : 2, "responseLength" : 758, "millis" : 0, "client" : "127.0.0.1", "user" : "" }
{ "ts" : ISODate("2012-10-26T18:27:07.506Z"), "op" : "query", "ns" : "analysis.system.indexes", "query" : { "expireAfterSeconds" : { "$exists" : true } }, "ntoreturn" : 0, "ntoskip" : 0, "nscanned" : 0, "keyUpdates" : 0, "numYield" : 0, "lockStats" : { "timeLockedMicros" : { "r" : NumberLong(698), "w" : NumberLong(0) }, "timeAcquiringMicros" : { "r" : NumberLong(6), "w" : NumberLong(7) } }, "nreturned" : 0, "responseLength" : 20, "millis" : 0, "client" : "0.0.0.0", "user" : "" }
{ "ts" : ISODate("2012-10-26T18:27:18.817Z"), "op" : "query", "ns" : "analysis.system.profile", "query" : { }, "ntoreturn" : 0, "ntoskip" : 0, "nscanned" : 4, "keyUpdates" : 0, "numYield" : 0, "lockStats" : { "timeLockedMicros" : { "r" : NumberLong(121), "w" : NumberLong(0) }, "timeAcquiringMicros" : { "r" : NumberLong(11), "w" : NumberLong(8) } }, "nreturned" : 4, "responseLength" : 1463, "millis" : 0, "client" : "127.0.0.1", "user" : "" }
{ "ts" : ISODate("2012-10-26T18:28:02.570Z"), "op" : "query", "ns" : "analysis.system.profile", "query" : { }, "ntoreturn" : 0, "ntoskip" : 0, "nscanned" : 5, "keyUpdates" : 0, "numYield" : 0, "lockStats" : { "timeLockedMicros" : { "r" : NumberLong(112), "w" : NumberLong(0) }, "timeAcquiringMicros" : { "r" : NumberLong(13), "w" : NumberLong(7) } }, "nreturned" : 5, "responseLength" : 1799, "millis" : 0, "client" : "127.0.0.1", "user" : "" }
{ "ts" : ISODate("2012-10-26T18:28:07.507Z"), "op" : "query", "ns" : "analysis.system.indexes", "query" : { "expireAfterSeconds" : { "$exists" : true } }, "ntoreturn" : 0, "ntoskip" : 0, "nscanned" : 0, "keyUpdates" : 0, "numYield" : 0, "lockStats" : { "timeLockedMicros" : { "r" : NumberLong(680), "w" : NumberLong(0) }, "timeAcquiringMicros" : { "r" : NumberLong(5), "w" : NumberLong(7) } }, "nreturned" : 0, "responseLength" : 20, "millis" : 0, "client" : "0.0.0.0", "user" : "" }
{ "ts" : ISODate("2012-10-26T18:28:11.608Z"), "op" : "query", "ns" : "analysis.system.profile", "query" : { }, "ntoreturn" : 0, "ntoskip" : 0, "nscanned" : 7, "keyUpdates" : 0, "numYield" : 0, "lockStats" : { "timeLockedMicros" : { "r" : NumberLong(117), "w" : NumberLong(0) }, "timeAcquiringMicros" : { "r" : NumberLong(10), "w" : NumberLong(7) } }, "nreturned" : 7, "responseLength" : 2504, "millis" : 0, "client" : "127.0.0.1", "user" : "" }
{ "ts" : ISODate("2012-10-26T18:28:51.589Z"), "op" : "command", "ns" : "analysis.$cmd", "command" : { "profile" : 0 }, "ntoreturn" : 1, "keyUpdates" : 0, "numYield" : 0, "lockStats" : { "timeLockedMicros" : { "r" : NumberLong(0), "w" : NumberLong(24) }, "timeAcquiringMicros" : { "r" : NumberLong(0), "w" : NumberLong(11) } }, "responseLength" : 58, "millis" : 0, "client" : "127.0.0.1", "user" : "" }
谢谢