Django default=timezone.now + delta

default takes a callable, so you just need to write a function to do what you want and then provide that as the argument:

def one_day_hence():
    return timezone.now() + timezone.timedelta(days=1)

class MyModel(models.Model):
    ...
    key_expires = models.DateTimeField(default=one_day_hence)

(As discussed here, resist the temptation to make this a lambda.)

Leave a Comment