Reputation: 1244
If I have following order in raw sqlite in flask app :
g.db.execute("INSERT INTO tbl_email (name,email,message,timestamp,was_sent,place,read) VALUES (?,?,?,DATETIME('now','localtime'),?,?,?)", db_save)
What is Equivalent in flask sqlalchemy for inserting `DATETIME('now','localtime')
Thank you very much
Upvotes: 0
Views: 3108
Reputation: 2887
In Flask-SQLAlchemy you'd have set the model like this:
class Foo(db.Model):
date_time = db.Column(db.DateTime(timezone=True), default=datetime.datetime.utcnow)
Maybe replacing datetime.datetime.utcnow
for a function that returns your local time. SQLAlchemy takes charge of setting the value upon save.
Upvotes: 2