我想在提交Post
模型的实例时运行一个函数。我想在它们提交后的任何时间运行它,所以我不想在任何地方显式调用该函数。我该怎么办?def notify_subscribers(post):
""" send email to subscribers """
...
post = Post("Hello World", "This is my first blog entry.")
session.commit() # How to run notify_subscribers with post as argument
# as soon as post is committed successfully?
post.title = "Hello World!!1"
session.commit() # Run notify_subscribers once again.
我想在提交Post模型的实例时运行一个函数。我想在它们提交时随时运行它,所以我不想在任何地方显式调用该函数。我怎样才能做到这一点? ...
after_commit
event(这是两种方式都发送信号的时间。)>]当调用after_commit
事件时,会话不在活动事务中,因此无法发出SQL