多个模型或查询集的外键 [英] ForeignKey to multiple Models or Queryset

查看:18
本文介绍了多个模型或查询集的外键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以为多个模型创建 ForeignKey.我想从不同的模型中进行选择,例如零件和机器模型.

It is possible to make a ForeignKey to more than one model. I want to choose from different models like Parts and Machines Model.

我阅读这篇文章是为了将多个模型组合到一个列表中:如何在 Django 视图中组合 2 个或多个查询集?

I read this to combine multiple models into one list: How to combine 2 or more querysets in a Django view?

我怎样才能以某种方式获得该列表的外键?

How can I get foreign key to that list somehow?

推荐答案

我知道你在一年前问过这个问题,但我遇到了类似的问题,我想为未来的读者分享一个解决方案的链接.

I know that you asked this over year ago, but I had a similar problem and I want to share a link to the solution for future readers.

通常contenttypes 框架 解决了这个问题,我猜这就是丹尼尔·罗斯曼所说的.

Generally the contenttypes framework solves this problem, and I guess this is what Daniel Roseman was talking about.

如何在 Django 中使用动态外键?

这篇关于多个模型或查询集的外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆