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

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -