2

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.

Ethan
  • 707
  • 3
  • 8
  • 17

1 Answers1

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