There is a page demonstrates how to do it when using Elixir:
http://beachcoder.wordpress.com/2007/05/02/adding-event-callbacks-to-sqlalchemyelixir-classes/
But I don't use Elixir, I just use sqlalchemy
directly, and define my models as:
Base = declarative_base()
class User(Base):
__tablename__ = "users"
...
def send_email(self):
# send email to the user
And what I want to do is:
class User(Base):
__tablename__ = "users"
...
before_insert('init_user', 'send_email')
before_delete('something_before_delete')
def init_user(self):
# init some data of the user
def send_email(self):
# send email to the user
def something_before_delete(self):
# something before delete
Note the before_insert
and before_delete
methods. What should I do?