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