Reputation: 747
Is there a way to pass a date to datafield that overrides auto_now? I want to only use auto_now if a date is not passed.
Upvotes: 2
Views: 1026
Reputation: 1187
According to the docs:
Note that the current date is always used; it’s not just a default value that you can override. https://docs.djangoproject.com/en/2.0/ref/models/fields/#datefield
So just don't use auto_now, use default, for example:
from django.utils import timezone
class YourModel(models.Model):
date_approved = models.DateField(default=timezone.now)
Upvotes: 4