可以在models.py里设置auto_now_add=True,如下所示:
class MyModel(models.Model): date_created = models.DateField(auto_now_add=True)
这样在新增MyModel对象时, date_created字段会自动设置为当前时间。
可以在models.py里设置auto_now_add=True,如下所示:
class MyModel(models.Model): date_created = models.DateField(auto_now_add=True)
这样在新增MyModel对象时, date_created字段会自动设置为当前时间。