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.
Asked
Active
Viewed 912 times
1 Answers
3
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)

Basalex
- 1,147
- 9
- 20