问题
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.
回答1:
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)
来源:https://stackoverflow.com/questions/50191848/overriding-django-auto-now-in-datefiled