我想将created_at (auto_now_add = True)
和updated_at (auto_now = true)
字段另存为 epoch
class EpochTest(models.Model):
name = models.CharField(max_length=32)
# Auto-update Field
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
我该怎么做?
答案 0 :(得分:0)
django不会将日期时间存储在unix-timestamp中,您必须手动进行操作,您可以通过
实现datetime.datetime.now().timestamp()
datetime.datetime.utcnow().timestamp()
,您还可以参考文档here