开发者

Setting a model attribute to some sql value in Django

I have a model called job and I want to set a datetime attribute (started_time) to MySQL now() value. how can I do that in Django?

I don't want to use the model auto_now or auto_now_add methods, since I have other applications who 开发者_运维百科share the same DB and I don't want to handle timezones, thus I want to delegate that to MySQL


Don't use auto_now/auto_add_now, they are problematic. Instead, do this:

  started_time = models.DateTimeField(default=datetime.utcnow)

-- assuming that you're working with timestamps in UTC.


Use MySQL trigger.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜