Django - auto_now=True 不适用于自定义操作
我的模型有以下字段。每当该模型发生变化时,它都必须更新。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以在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 callsave()
. Thus, it's pretty normal that the DateField is not updated byauto_now
(which updates on save() calls)http://docs.djangoproject.com/en/1.2/ref/models/querysets/#update-kwargs