Django admin Many2Many 小部件定制
我需要自定义 Django Admin 的 m2m 小部件的显示方式,但我有点不知从哪里开始。我尝试从 django.forms 和 django.contrib.admin.wigets 中继承几个小部件,但似乎没有任何效果。
这是我正在寻找的内容的描述 https://i.sstatic.net/81AY3.png。
任何帮助表示赞赏。
I need to customize how the m2m widget for Django Admin gets displayed but I am kind of stumped where to start. I have tried subclassing couple of widgets from django.forms
and django.contrib.admin.wigets
but nothing seems to be working.
Here's a depiction of what I am looking for https://i.sstatic.net/81AY3.png.
Any help appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这看起来像是只用 JavaScript 就可以实现的事情。要将您自己的 JavaScript 添加到 Django 管理,请参阅 ModelAdmin 媒体定义。
That looks like the kind of thing that could be achieved with JavaScript alone. For adding your own JavaScript to the Django admin, see the documentation for ModelAdmin media definitions.
这就是我想出来的。它完成了大部分工作。但是,添加新项目时列表不会更新,并且更改项目不会重定向回原始页面。
/your_app/forms.py
/your_media/js/custom_m2m.js
如您所见,上面的脚本使用了一些硬编码的路径。任何改进都会有帮助。
This is what I came up with. It does most of the work. However, the list does not get updated when a new item is added and changing an item does not redirect back to the original page.
/your_app/forms.py
/your_media/js/custom_m2m.js
As you can see, the above script uses some hardcoded paths. Any improvement would be helpful.