我有一个简单的用户模型,定义如下:
# 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()
当我创建一个新的用户对象时,我的date_updated
字段被设置为当前时间.我想要做的是,使whenever我保存对我的用户对象的更改,我的date_updated
字段自动设置为当前时间.
我已经翻遍了文档,但无论如何,我似乎找不到任何与此有关的参考资料.我对SQLAlChemy非常陌生,所以我确实没有以前的经验可供借鉴.
希望得到一些反馈,谢谢.