title: onupdate based on another field with sqlalchemy declarative base
body: <p>I use sqlalchemy with the pyramid framework, and i want to link a person to his geographical department using his postcode.
  So i try to use the onupdate argument when defining the department_id column define the department_id.
  see fallowing code:</p>
  
  <pre><code>from datetime import date
  from emailing.models import Base, DBSession
  from sqlalchemy import Column, Integer, Unicode, Text, DateTime, Sequence, Boolean, Date, UnicodeText, UniqueConstraint, Table, ForeignKey
  from sqlalchemy.orm import scoped_session, sessionmaker, column_property, relationship, backref
  from sqlalchemy.sql import func
  
  class Person(Base):
      __tablename__ = u'person'
      id = Column(Integer, primary_key=True)
  
      firstName = Column(Unicode(255))
      lastName = Column(Unicode(255))
  
      created_at = Column(Date, default=func.now())
      updated_at = Column(Date, onupdate=func.now())
  
      department_id = Column(Integer(), ForeignKey('department.id'), onupdate=dep_id_from_postcode)
      department = relationship("Department", backref='persons')
  
  
      __table_args__ = (UniqueConstraint('firstName', 'lastName'), {})
  
  
      def dep_id_from_postcode(self):
          return int(self.postcode[:2]) 
  </code></pre>
  
  <p>on update for the updated_at field works fine, but for the deparment_id field it tell my:</p>
  
  <blockquote>
    <p>NameError: name 'dep_id_from_postcode' is not defined</p>
  </blockquote>
  
  <p>i've found documentation about python executed function here: <a href="http://docs.sqlalchemy.org/en/latest/core/schema.html?highlight=trigger#python-executed-functions" rel="nofollow">http://docs.sqlalchemy.org/en/latest/core/schema.html?highlight=trigger#python-executed-functions</a>
  but nothing that uses another field to use in onupdate argument.</p>
  
  <p>i hope i'm clear enought as i'm not a "natural english speaker"
  Thank you all</p>