有没有办法在 Django 中为内联管理表单创建单独的页面?
假设我有一个模型 A。然后,我有几个模型 B、C、D、E 等,每个模型都有一个模型 A 的外键。我知道我可以将 B、C、D 等设置为模型 A 的内联,这样当我创建模型 A 时,它将显示用于为每个子模型添加多个项目的表单集,但我认为这会导致页面相当混乱且非常大。
有没有办法以某种方式将每个表单集放在单独的页面上,而不是将所有这些表单集内联在同一页面上?换句话说,是否存在从模型 A 到创建/编辑关联模型 B、创建/编辑关联模型 C 等的链接?
谢谢!
Lets say i have a model A. Then, i have several models B, C, D, E etc that each have a foreignKey to model A. I know that i can set B, C, D etc as inlines to model A so that when i create a model A it will show formsets for adding multiple items for each subModel, but i think this would make a fairly cluttered and very large page.
Is there a way to somehow, instead of having all of these formsets inline on the same page, to have each formset on a separate page? in other words, there would be links from model A to create/edit associate model B's, create/edit associated model C's, etc?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简单的答案是创建一个文件:
在更改表单中,您执行以下操作:
这有点原始,但它可以满足您的要求。列表和复杂的聚合比较棘手,您需要测试原始数据是否存在,以确保不会生成模板错误。
The trivial answer would be to create a file:
Inside your change form, you do this:
It's kinda primitive, but it does what you want. Lists and complex aggregations are trickier, and you'd want to test for original's presence to make sure you don't generate template errors.
我正在寻找一种方法来做完全相同的事情。看起来答案可能是“代理模型”。建议作为此 Stack Overflow 查询的答案:
...这个查询询问同一模型的多个管理列表:
有关代理模型的文档:
我自己是 Django 的新手,所以一旦我让它工作,我会发布更完整的回复。
I’m looking for a way to do exactly the same thing. It looks like the answer might be 'proxy models'. It's suggested as an answer to this Stack Overflow query:
…and this query asking about multiple admin lists for the same model:
Documentation on Proxy Models here:
I’m a newcomer to Django myself, so will post a more complete reply once I get it to work.