title: How Can I Automatically Populate SQLAlchemy Database Fields? (Flask-SQLAlchemy)
body: <p>I've got a simple User model, defined like so:</p>
  
  <pre><code># models.py
  from datetime import datetime
  from myapp import db
  
  class User(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    email = db.Column(db.String(100), unique=True)
    password = db.Column(db.String(100))
    date_updated = db.Column(db.DateTime())
  
    def __init__(self, email, password, date_updated=None):
      self.email = email
      self.password = password
      self.date_updated = datetime.utcnow()
  </code></pre>
  
  <p>When I create a new User object, my <code>date_updated</code> field gets set to the current time. What I'd like to do is make it so that <em>whenever</em> I save changes to my User object my <code>date_updated</code> field is set to the current time automatically.</p>
  
  <p>I've scoured the documentation, but for the life of me I can't seem to find any references to this. I'm very new to SQLAlchemy, so I really have no prior experience to draw from.</p>
  
  <p>Would love some feedback, thank you.</p>