Here are the examples of the python api sqlalchemy.sa_event.listens_for taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1 Examples
3
Example 1
Project: kittystore Source File: model.py
@sa_event.listens_for(Thread, 'before_insert')
def Thread_before_insert(mapper, connection, target):
"""Auto-set the active date from the last email in thread"""
if target.date_active is not None:
return
session = object_session(target)
last_email_date = session.query(Email.date).order_by(
desc(Email.date)).limit(1).scalar()
if last_email_date:
target.date_active = last_email_date
else:
target.date_active = datetime.datetime.now()