Created
March 22, 2018 06:32
-
-
Save UBarney/d5d0003f87b1436489923f5a5d93710c to your computer and use it in GitHub Desktop.
force update field of auto now
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
# from https://stackoverflow.com/questions/7499767/temporarily-disable-auto-now-auto-now-add | |
# my model | |
class FooBar(models.Model): | |
title = models.CharField(max_length=255) | |
updated_at = models.DateTimeField(auto_now=True, auto_now_add=True) | |
# my tests | |
foo = FooBar.objects.get(pk=1) | |
# force a timestamp | |
lastweek = datetime.datetime.now() - datetime.timedelta(days=7) | |
FooBar.objects.filter(pk=foo.pk).update(updated_at=lastweek) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment