What is equivalent to Django auto_now, auto_now_add in SQLAlchemy?

In Django, we can use these 2 parameters when creating a date column:

DateField.auto_now Automatically set the field now every time the object is saved. Useful for timestamps with the latest change. Note that the current date is always used; it is not only the default value that you can override.

DateField.auto_now_add. Automatically set the field now when the object is first created. Useful for creating timestamps. Note that the current date is always used; it is not only the default value that you can override.

How to do it in SQLAlchemy?

+9
python date django sqlalchemy
source share
1 answer

Finally, after checking the SQLAlchemy document, it should be like this:

Column('created_on', DateTime, default=datetime.datetime.now) Column('last_updated', DateTime, onupdate=datetime.datetime.now) 

The dock is here:

http://docs.sqlalchemy.org/en/latest/core/defaults.html#python-executed-functions

+23
source share

All Articles