Setting auto_now
and auto_now_add
to True will automatically set a DateField
or a DateTimeField
to the current date and time. This works great for "created" and "modified" fields.
However, suppose you're importing content from another system, and you want to maintain the existing timestamps. If you're using auto_now...
, then it won't work--you can't override them. Ouch.
Instead, set default
to the timezone.now
or date.today
function.
from datetime import date
from django.utils import timezone # <-- you need Django's timezone module
created = models.DateTimeField(default=timezone.now)
created = models.DateField(default=date.today)
See the Django docs.