import mongoengine
class Model1(mongoengine.DynamicDocument):
name = mongoengine.StringField()
addr = mongoengine.EmbeddedDocumentField(Model2)
class Model2(mongoengine.EmbeddedDocument):
loc = mongoengine.StringField()
# do some stuff
def save(self, *args, **kwargs):
print "test line print...."
super(Model2, self).save(*args, **kwargs)
现在我保存Model1
个实例。它不会调用保存方法
m2 = Model2(loc='some text')
m1 = Model1(name='name')
m1.addr = m2
m1.save()
如果我试图明确地在Model2上调用save方法,它会抱怨NoneType object has no attr save
答案 0 :(得分:0)