Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法获取在表中添加元组的时间?或者更具体地说,在给定范围之间具有时间戳的元组?
你可以auto_now_add=True在一个DateField
auto_now_add=True
DateField
from django.db import models class MyModel(models.Model): date = models.DateField(auto_now_add=True)
比根据文档
首次创建对象时自动将字段设置为现在。用于创建时间戳。请注意,始终使用当前日期;它不仅仅是您可以覆盖的默认值。