モデルのインスタンスを保存しようとしていますが、
Invalid EmbeddedDocumentField item (1)
アイテムのIDはどこ1
ですか(私は思う)。
モデルは次のように定義されます
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()
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" : "" }
ありがとう