title: Object-based default value in SQLAlchemy declarative
body: <p>With SQLAlchemy, it is possible to add a default value to every function. As I understand it, this may also be a callable (either without any arguments or with an optional ExecutionContext argument).</p>
  
  <p>Now in a declarative scenario, I wonder if it is somehow possible to have a default function which is called with the <em>object</em> that is being stored. I.e. possibly like so:</p>
  
  <pre><code>Base = sqlalchemy.ext.declarative.declarative_base()
  class BaseEntity(Base):
      value = Column('value', String(40), default=BaseEntity.gen_default)
  
      def gen_default(self):
          # do something with self, for example
          # generate a default value using some other data
          # attached to the object
          return self.default_value
  </code></pre>
  
  <p>Is something like this possible? Or do I have to somehow set up an <em>before-insertion</em> hook for this (how?)?</p>