在 Django 前端删除多行
我将在 django 中实现多重删除(通过选择框)视图。
我知道 django.contrib.admin.actions 中有一个视图,但我无法将其移植到前端。
我应该在表单中分配对象 ID 并将它们发布到我的删除视图,然后使用 .delete() 吗?
我以前没有接触过编程,Django 是我开始编程冒险的框架。
我正在寻找示例(Django view + html),但找不到任何示例。
I am going to implment a multi delete (via select boxes) view in django.
I know there's a view in django.contrib.admin.actions but I can't port this to frontend.
Should I assign object id's in the form and POST these to my delete view and then use .delete() ?
I haven't been programming before, and Django is the framework I start my programming adventure.
I was looking for example (for Django view + html) but couldn't find any.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
modelformset
并仅使用delete
选项手动呈现表单:https://docs. djangoproject.com/en/dev/topics/forms/formsets/#manually-rendered-can-delete-and-can-order替代解决方案:
使用
modelformset
创建一堆带有删除复选框的表单如下所示:Using a
modelformset
and manually rendering the form with just thedelete
options: https://docs.djangoproject.com/en/dev/topics/forms/formsets/#manually-rendered-can-delete-and-can-orderAlternative solution:
Using a
modelformset
to create a bunch of forms with a delete checkbox like this: