Django DateTimeField auto_now_add not working

前端 未结 4 788
花落未央
花落未央 2021-02-04 08:04

In one of the model i have set one timestamp field as follows:

created_datetime = models.DateTimeField(auto_now_add = True)

While in shell i am

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-04 08:23

    As far as I know, best practice for default datetimes is to use the following:

    created_datetime = models.DateTimeField(default=datetime.datetime.now)
    

    Don't forget to import datetime

提交回复
热议问题