Skip to content

Instantly share code, notes, and snippets.

@cansadadeserfeliz
Created July 16, 2014 17:00
Show Gist options
  • Select an option

  • Save cansadadeserfeliz/e19c84f127e91bc33fb5 to your computer and use it in GitHub Desktop.

Select an option

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
class MyModel(models.Model):
updated_at = models.DateTimeField(
default=timezone.now,
auto_now=True,
)
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