django does django have an automatic timestamp create/update field like cakephp?

后端 未结 2 1671
梦如初夏
梦如初夏 2021-02-07 08:36

having used cakephp in the past, one thing (perhaps the only thing?) i liked about it was that it had a \"create\" and \"update\" timestamp capability that was lovely - simply p

相关标签:
2条回答
  • 2021-02-07 08:52

    Sure it has!

    Check auto_now and auto_now_add in the doc

    0 讨论(0)
  • 2021-02-07 09:08

    It is not added to your model built-in in every table. You must add it as field to your model.

    class Message(models.Model):
    
        created_at = models.DateTimeField(auto_now_add=True)
        updated_at = models.DateTimeField(auto_now=True)
    

    Message in this case your table's name.

    0 讨论(0)
提交回复
热议问题