Django - 向作者添加相关书籍
让我们以标准示例为例,
class Author(models.Model):
name = models.CharField(max_length=100)
class Book(models.Model):
title = models.CharField(max_length=100)
author = models.ForeignKey(Author)
#... Many other fields ...
在作者
更改页面的管理界面上,我希望能够添加/编辑他的书籍
。
你要告诉我 RTFM 并使用 InlineModelAdmin< /a>.
但是等等,正如您所看到的,Books
中有“许多其他字段”,并且它不容易编辑。
我的设想是能够简单地在作者更改页面中显示书名,并提供添加或编辑他的书籍的链接。我怎样才能做到这一点?
Lets take the standard example
class Author(models.Model):
name = models.CharField(max_length=100)
class Book(models.Model):
title = models.CharField(max_length=100)
author = models.ForeignKey(Author)
#... Many other fields ...
On the admin interface from the Author
change page, I'd like to be able to add/edit his Books
.
There you are going to tell me please RTFM and use a InlineModelAdmin.
But wait, as you can see there are "Many other fields" in Books
and it will not be easily editable.
What I imagined is to be able to simply display the book titles in the Author
change page, and supply links to add or edit his books. How can I do that ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以覆盖
change_view
和/或编辑change_form模板。您可以参考文档中有关此主题的部分: 覆盖与替换管理模板
可以在此处找到一些更具体的信息:显示 django admin 中对象的完整更改表单的链接< /a>
You can override the
change_view
and/or edit the change_form template.There's a section in the docs you can consult on this topic: Overriding vs. replacing an admin template
Some more specific information can be found here: Display link to full change form for object in django admin