Django default=timezone.now() saves records using “old” time

前端 未结 2 1710
伪装坚强ぢ
伪装坚强ぢ 2020-12-18 18:48

This issue has been occurring on and off for a few weeks now, and it\'s unlike any that has come up with my project.

Two of the models that are used have a timestam

2条回答
  •  悲&欢浪女
    2020-12-18 19:35

    Just ran into this last week for a field that had default=date.today(). If you remove the parentheses (in this case, try default=timezone.now) then you're passing a callable to the model and it will be called each time a new instance is saved. With the parentheses, it's only being called once when models.py loads.

提交回复
热议问题