I figured it out.
The issue was that the field renew_date
had the argument auto_now
set to True
as such:
renew_date = models.DateField(auto_now=True, editable=False)
I understood auto_now
to mean that the current date will be used when creating the object, but it turns out that's not the case:
DateField.auto_now
Automatically set
the field to now every time the object
is saved. Useful for "last-modified"
timestamps. Note that the current date
is always used; it's not just a
default value that you can override.
From django docs.
What I needed was auto_now_add
which:
Automatically set the field to now
when the object is first created.
Useful for creation of timestamps.
Note that the current date is always
used; it's not just a default value
that you can override.
So, after changing my renew_date
field:
renew_date = models.DateField(auto_now_add=True, editable=False)
it all works, just fine :)
>>> g = SelectStatProfile.objects.get(pk=3)
>>> g.renew_date
datetime.date(2010, 4, 11)
>>> from datetime import date, timedelta
>>> g.renew_date = date.today()+timedelta(days=365)
>>> g.renew_date
datetime.date(2011, 4, 11)
>>> g.save()
>>> g.renew_date
datetime.date(2011, 4, 11)