title: Tracking model changes in SQLAlchemy
body: <p>I want to log every action what will be done with some SQLAlchemy-Models.</p>
  
  <p>So, I have a after_insert, after_delete and before_update hooks, where I will save previous and current representation of model,</p>
  
  <pre><code>def keep_logs(cls):
      @event.listens_for(cls, 'after_delete')
      def after_delete_trigger(mapper, connection, target):
          pass
  
      @event.listens_for(cls, 'after_insert')
      def after_insert_trigger(mapper, connection, target):
          pass
  
      @event.listens_for(cls, 'before_update')
      def before_update_trigger(mapper, connection, target):
          prev = cls.query.filter_by(id=target.id).one()
          # comparing previous and current model
  
  
  MODELS_TO_LOGGING = (
      User,
  )
  for cls in MODELS_TO_LOGGING:
      keep_logs(cls)
  </code></pre>
  
  <p>But there is one problem: when I'm trying to find model in before_update hook, SQLA returns modified (dirty) version.
  How can I get previous version of model before updating it? 
  Is there a different way to keep model changes?</p>
  
  <p>Thanks!</p>