from ming.odm.mapper import MapperExtension
class MyExtension(MapperExtension):
def after_insert(self, obj, st):
print "instance %s after insert !" % obj
class MyMappedClass(MappedClass):
class __mongometa__:
session = session
name = 'my_mapped_class'
extensions = [ MyExtension ]
_id = FieldProperty(schema.ObjectId)
data = FieldProperty(schema.String,if_missing='')
我尝试使用官方 Ming 文档中的 MapperExtension。在创建文档时我得到:
t = model.MyMappedClass()
model._session.flush()
TypeError: before_insert() takes exactly 3 arguments (4 given)