管理列表删除和模型delete()方法
我在我的模型中定义了 delete() 方法。我用它来清除缓存和删除拇指。当我在管理中删除一个元素时,在其详细信息(编辑模式)中,缓存将被清除,所有拇指都将被删除。 但是,当我想一次删除多个元素时 - 检查元素列表上的复选框 - 元素被删除,但 cahce 和缩略图没有被删除,所以我的模型删除方法没有创建:/
我该如何修复它?
I have defined delete() method in my model. I use it to clear cache and delete thumbs. When I delete an element in admin, in it's details (edit mode) cache is cleared and all thumbs are deleted.
But, when i want to delete several elements at once - checking checkboxes on the elements list - elements are deleted, but cahce and thumbnails aren't deleted, so my model delete method isn't made:/
How can I fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它位于文档的第一部分。出于效率原因,Django Admin 对查询集对象调用
delete
。这完全绕过了每个实例的删除方法。阅读文档。It's in the very first section of the documentation. Django Admin calls
delete
on the queryset object for efficiency reasons. That totally bypasses each instances delete method. Read the docs.如文档中所述,您需要重写
delete selected
操作:As described in the documentation, you need to override the
delete selected
action: