Created
July 16, 2014 17:00
-
-
Save cansadadeserfeliz/e19c84f127e91bc33fb5 to your computer and use it in GitHub Desktop.
Django: how to manually set/update a DateTimeField field with auto_now=True
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MyModel(models.Model): | |
| updated_at = models.DateTimeField( | |
| default=timezone.now, | |
| auto_now=True, | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import datetime | |
| MyModel.objects.filter(id=my_model_object.id).update( | |
| updated_at=datetime.datetime(2014, 1, 12, 15, 15), | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment