Django 管理站点反向外键内联
我有这些模型:(
伪代码)
Course:
ForeignKey(Outline, null=True, blank=True)
ForeignKey(OutlineFile, null=True, blank=True)
Outline:
//data
OutlineFile:
//different data
情况是任何课程都可以有与之关联的大纲,和/或大纲文件,或两者都没有。一个大纲可以与多个课程关联,同样,一个大纲文件可以与多个课程关联。然而,一门课程最多只能有其中一个。
我想要的是让课程更改管理页面显示所有课程字段,以及每个大纲和大纲文件的下拉列表。如果随后选择其中一个,我希望显示该大纲的字段并可对其进行修改,就像内联字段一样。
我应该以某种方式重组我的模型,还是它们的结构已经足够了?无论如何,有没有办法在当前内联系统的范围内做我想做的事情?
最后,如果不可能,我从哪里开始以定制方式进行呢?
I have these models:
(pseudocode)
Course:
ForeignKey(Outline, null=True, blank=True)
ForeignKey(OutlineFile, null=True, blank=True)
Outline:
//data
OutlineFile:
//different data
The situation is that any course can have an Outline associated with it, and/or an OutlineFile, or neither. An Outline can be associated with multiple courses, similarly an OutlineFile can be associated with multiple courses. However, a course will only ever have at most one of each.
What I want is to have the Course change admin page show all the Course fields, and a drop down for each of Outline and OutlineFile. If one is then selected, I want the fields for that Outline to be displayed and modifiable, just like an inline field.
Should I be restructuring my models somehow, or are they structured adequately already? Is there anyway to do what I want within the confines of the current inlines system?
Lastly, if it's not possible, where do I start in doing it in a custom fashion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在以相反的方式进行操作:
当您创建 std 表单时,此模型结构将创建一个像您默认指定的下拉列表。
You are doing it the other way around:
When you create the std forms, this model structure will create a dropdown like you specify by default.