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

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

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -