django - datetime.now() not accurate -


i have django application automatically takes in timezone.now() value field in model. when run on localhost, works expected. however, when deployed onto digital ocean, timezone.now() takes value of time when started running server. why happen , how can work around this?

correction: django's timezone.now()

code have been helpful.

presumably using default argument field. problem have done this:

my_field = models.datefield(default=datetime.datetime.now()) 

which, due way python works, evaluated when class defined - ie when process starts. instead, should pass callable:

my_field = models.datefield(default=datetime.datetime.now) 

that is, without calling parentheses, , django know call on instantiation.


Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -