In django do models have a default timestamp field?

前端 未结 6 1335
误落风尘
误落风尘 2021-01-30 09:53

In django - is there a default timestamp field for all objects? That is, do I have to explicitly declare a \'timestamp\' field for \'created on\' in my Model - or is there a way

6条回答
  •  佛祖请我去吃肉
    2021-01-30 10:32

    I think i would go with

    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
    

    I need some clarifications on using

    class TimeStampedModel(models.Model):
        created_on = models.DateTimeField(auto_now_add=True)
    
        class Meta:
             abstract = True
    

提交回复
热议问题