Django admin ManyToManyField:提高change_form的可用性?
我的 Django 模型如下:
class Subject(models.Model):
name = models.CharField(max_length=35, unique=True)
class Book(models.Model):
title = models.CharField(max_length=400)
subject = models.ManyToManyField(Subject, related_name='books', blank=True, verbose_name="Subject")
有很多主题 - 大约 100 个。
在 Django 管理上编辑书籍记录时,很难看到特定书籍上存在哪些主题。
Django 管理提供了一个多选列表,这很棒,但是要查看一本书,您必须滚动整个选择列表。
如果以下任一情况会更好:
- 我可以在多选列表上方提供主题的只读列表,或者
- 多选列表以所选主题开始,然后有一个类似“----”的条目,然后继续其他科目。
有谁知道如何在 Django 中实现上述任一功能,以提高 Django 管理中 ManyToManyFields 的可用性?
谢谢!
I have Django models as follows:
class Subject(models.Model):
name = models.CharField(max_length=35, unique=True)
class Book(models.Model):
title = models.CharField(max_length=400)
subject = models.ManyToManyField(Subject, related_name='books', blank=True, verbose_name="Subject")
There are many Subjects - around 100.
When editing a Book record on the Django admin, it is very difficult to see which subjects are present on a particular book.
The Django admin offers a multi-select list, which is great, but to see for a book, you have to scroll through the entire select list.
It would be much better if either:
- I could offer a read-only list of the subjects above the multi-select list, or
- the multi-select list began with the selected subjects, then had an entry like '----', then continued with the other subjects.
Does anyone have any idea how I could implement either of the above in Django, to improve the usability of ManyToManyFields in the Django admin?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
filter_horizontal
(或filter_vertical
)。Use
filter_horizontal
(orfilter_vertical
).