简体   繁体   English

如何在单个模板中呈现两个模型的内容,其中一个模型由外键通过 django 中的另一个模型链接?

[英]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.

相关问题 如何在涉及两个外键链接模型的 django 模板中进行过滤摘要? - How to make a filtered summary in django template involving two models linked with foreign key? 从一个Django模型迁移到使用外键引用的两个模型 - Migrate from one django model to two models referenced with a foreign key 如何在 django 中模拟 model 的外键模型? - How to mock foreign key models of a model in django? 在django模型中的序列通过外键访问模型之间的模型如何修复我的模型? - Sequence in the django model access between model through foreign key to model how to fix my models? 通过另一个模型加入2个模型,它们有一个外键 - join 2 models through another model which they have a foreign key to it Django:当父模型有两个外键来自同一模型时,如何定义模型? - Django: How to define the models when parent model has two foreign keys come from one same model? 如何使用用户外键将模型表单保存到Django模型 - How to save a Model Form with a foreign key of User to django models 如何为由外键关联的两个模型创建单个ModelForm? - How to create single ModelForm for two models that are related by a Foreign Key? 如何为通过外键关联的两个模型创建单个表单? - How to create single Form for two models that are related by a Foreign Key? 如何建立一个具有不同模型的两个外键关系的模型 - How to make a model having two foreign Key relations with the different models
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM