Django - auto_now=True 不适用于自定义操作

发布于 2024-09-30 11:38:29 字数 179 浏览 0 评论 0原文

我的模型有以下字段。每当该模型发生变化时,它都必须更新。

Modified_at = models.DateTimeField(auto_now=True)

我编写了一个自定义操作来更改管理界面中该模型的状态。

除了管理界面中提到的自定义操作之外,此特定字段适用于所有类型的更新。有什么想法吗?

My Model has the following field. It has to update whenever there is a change in that model.

modified_at = models.DateTimeField(auto_now=True)

and I wrote a custom action to change the status of this model in the admin interface.

this particular field works fine for all kind of updates except the mentioned custom actions in the admin interface. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赠佳期 2024-10-07 11:38:29

你可以在django的文档中看到update()实际上并没有调用save()。因此,DateField 不被 auto_now 更新(在 save() 调用时更新)是很正常的

http://docs.djangoproject.com/en/1.2/ref/models/querysets/#update-kwargs

You can see in django's documentation that update() actually don't call save(). Thus, it's pretty normal that the DateField is not updated by auto_now (which updates on save() calls)

http://docs.djangoproject.com/en/1.2/ref/models/querysets/#update-kwargs

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文