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

前端 未结 2 1711
伪装坚强ぢ
伪装坚强ぢ 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:30

    Just set the parameter auto_now_add like this.

    timestamp = models.DateTimeField(auto_now_add=True)
    

    Update:

    Please don't use auto_now_add. It is not the recommended way, instead do this:

    from django.utils import timezone
    
    timestamp = models.DateTimeField(default=timezone.now)
    

提交回复
热议问题