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
Post a Comment