[英]How to render contents of two models in a single template where one model is linked by Foreign Key through another in django?
I am trying to create a site for financial purpose.我正在尝试创建一个用于财务目的的网站。 I have two models "Company" and "Reports".
我有两个模型“公司”和“报告”。 Reports model has a foreign key linked to Company.
报告模型有一个与公司链接的外键。 I want to render contents of Company and Reports in a single template in a detail view.
我想在详细视图中的单个模板中呈现公司和报告的内容。 When i try to render only one of the model's content is shown not both.. Is there any solution to this?
当我尝试只渲染一个模型的内容时,不会同时显示两者.. 有什么解决方案吗?
在没有更多细节的情况下很难给出一个更好的例子,但它看起来像这样......
{{ reports_object.company_foreignkey.company_field }}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.