The problem is that I cannot figure out how to use SQLAlchemy to notify me when an object transitions to a new state.
I am using SQLAlchemy ORM (declarative) to update an object:
class Customer(declarative_base()):
__table_name__ = "customer"
id = Column(Integer, primary_key=True)
status = Column(String)
I want to know when an object enters a state. In particular, after the UPDATE was released and when the state changed. For instance. Customer.status == 'registered', and earlier he had a different condition.
I am currently doing this with an attribute event 'set':
from sqlalchemy import event
from model import Customer
def on_set_attribute(target, value, oldvalue, initiator):
print target.status
print value
print oldvalue
event.listen(
Customer.status,
'set',
on_set_attribute,
propagate=True,
active_history=True)
, "set", , value oldvalue. , target , .
? !