In django do models have a default timestamp field?

前端 未结 6 1330
误落风尘
误落风尘 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:41

    If you want to be able to modify this field, set the following instead of auto_now_add=True:

    For Date

    from datetime import date
    
    models.DateField(default=date.today)
    

    For DateTime

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

提交回复
热议问题