python - Django migration with DateTimeField and timedelta default -


i'm having trouble setting default datetime on 1 of django models

from django.db import models django.utils import timezone  class mymodel(models.model):     my_datetime = models.datetimefield(default=timezone.now() + timezone.timedelta(+14)) 

the problem everytime run makemigrations creates new migration on field, default value serialized value equals now.

migrations.alterfield(     model_name='mymodel',     name='my_datetime',     field=models.datetimefield(default=datetime.datetime(2016, 2, 4, 5, 56, 7, 800721, tzinfo=utc)),     ) 

is there anyway can set default value datetimefield that's in future?

problem put result of expression in default. instead need assign default callable want. here example:

from django.db import models django.utils import timezone  def default_time():     return timezone.now() + timezone.timedelta(+14)  class mymodel(models.model):      my_datetime = models.datetimefield(default=default_time) 

Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -