具有多个选择的 Django 管理复选框
我有一个 Django 应用程序。非常基本的一个。
在模型中,我有一个项目类和一个组类。这些组具有多对多的项目:
items = models.ManyToManyField(item, verbose_name="list of items", max_length=100000, blank=True)
当我将其添加到管理部分时,我希望有一个具有多个选择的复选框。这可能吗。我看过的所有解决方案也不会将其播种在管理页面的上下文中。 Django 管理页面就是我所需要的,因为我没有制作任何自定义的、面向公众的页面。
用多个复选框替换多选框的最简单和最简单的解决方案是什么。
附言。我对 Django 相对缺乏经验,所以我需要看看我需要在模型和管理中导入什么。
谢谢
I have a Django app. Pretty basic one at that.
In the model I have a class for items and a class for groups. The groups has a many to many for the items:
items = models.ManyToManyField(item, verbose_name="list of items", max_length=100000, blank=True)
When I add this to the admin section I would like to have a checkbox with multiple select. Is this possible. All of the solutions I have looked at don't sow it in the context of an admin page too. The Django admin page is all I need it to work on as I am not making any custom, public facing pages.
What is the easiest and most simple solution to replace the multiple select box with a multiple checkbox.
PS. I am relatively in-experienced with Django so I need to see what I need to import in the model and admin.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您知道如何在标准模型表单中执行此操作,那么您也知道如何在管理页面中执行此操作,因为它们基于普通表单。
只需像平常一样定义表单,然后告诉管理员将其用于您的模型:
If you know how to do it for a standard modelform, you know how to do it in an admin page too, as they are based on normal forms.
Just define the form as normal, then tell the admin to use it for your model:
基于覆盖管理模板的方式
way based on overriding admin templates