在我得蓝图当中我定义了 一个接受者
# -*- coding: utf-8 -*- from flask_sqlalchemy import models_committed # flag = True # if flag: def on_models_committed(sender, changes): print u'我是订阅者,我要触发任务' for obj, change in changes: if change == 'insert' and hasattr(obj, '__commit_insert__'): obj.__commit_insert__() elif change == 'update' and hasattr(obj, '__commit_update__'): obj.__commit_update__() elif change == 'delete' and hasattr(obj, '__commit_delete__'): obj.__commit_delete__() models_committed.connect(on_models_committed)
然后哦在create_app 当中的__init__.py 导入了我蓝图中的这个方法
在models.py 中定义了__commit_update__()方法来执行处理逻辑
但是现在信号无法触发,求问哪里出错了?
问题解决方式 db.session.query(ClassModel).filter( ClassModel.id == ids).delete() 修改成 db.session.query(ClassModel).filter( ClassModel.id == ids).first().delete() classModel(db.Model): ..... def delete(self): db.session.delete(self) db.session.commit()
加上以上修改能够正确的捕捉到信号的触发了, 但是不知道原理是啥? query对象的删除,和model对象的删除的级别问题么, 内置信号是基于db 这一层级别的吗?
添加一行这个看下:
http://www.springframework.org/schema/mvc
全部是:
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd