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.
我有一个模型问题,其中包含一个名为 flags 的 IntegerField 和一个名为 pub_date 的日期时间字段。pub_date 设置为 auto_now=True。 我有一个更改标志字段的视图。当我更改标志并对 Question 对象执行 .save() 时,其发布日期更改为现在。 我不希望仅在创建 pub_date 时设置它,而不是在我更改记录中的某些数据时设置。我怎样才能做到这一点? 如果您需要查看我的代码,请告诉我,因为我认为您不需要在这里。
你应该设置auto_now_add = True
auto_now_add = True
您可以在视图中删除 auto_now=True 并在需要时手动设置该字段。