As j0ker said, if you want automatic update of the timestamp, use the auto_now
option. E.g. date_modified = models.DateTimeField(auto_now=True)
.
If you want to set the field to now only when the object is first created you should use:
date_modified = models.DateTimeField(auto_now_add=True)
Or if you want to do it manually, isn’t it a simple assignment with python datetime.now()
?
from datetime import datetime
obj.date_modified = datetime.now()