Trying to set a timestamp for a key expiration in Django model and bumped into this issue :
My current code :
key_expires = models.DateTimeField(de
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
.)