简体   繁体   English

用Django连接两个数据库表

[英]Joining two database tables with django

I am doing several measurements of voltage, resistance, frequency, etc. of a device. 我正在对设备的电压,电阻,频率等进行多次测量。 I want to have a table for each measurement as well as a main table with the serial number of the device and boolean values if it has passed the tests. 我希望有一个用于每个测量的表,以及一个具有设备序列号和布尔值的主表(如果通过了测试)。

I planned to have the structure similar to this: 我计划具有类似于以下的结构:

create table volt(serial char(20),v1 float(10),v2 float(10)....)
create table resistance(serial char(20),r1 float(10),r2 float(10)....)
create table device(serial char(20),freq boolean(),tx boolean....)

I admit to not having a lot of experience with django and I have no idea how to create a model like this. 我承认对django没有太多的经验,我也不知道如何创建这样的模型。 I tried making seperate classes and using foreignKey, but for that I'd have to create the resistance and volt measurements first. 我尝试制作单独的类并使用foreignKey,但是为此,我必须首先创建电阻和电压测量值。

It is possible to store the measurement values as comma seperated strings as well, but I'd rather have it in a proper database. 也可以将测量值存储为逗号分隔的字符串,但我宁愿将其保存在适当的数据库中。

Any hints? 有什么提示吗?

您的VoltageResistance等模型应具有Device模型的ForeignKey

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM