Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python django的ORM查询_Python_Django - Fatal编程技术网

Python django的ORM查询

Python django的ORM查询,python,django,Python,Django,我对django中的ORM查询相当陌生。我使用下面的sql从数据库中获取数据 Select * from subnets_subnet as sb left join subnets_subnetoption as sbo on sb.id = sbo.subnet_id left join options_value as ov on ov.id=sbo.value_id left join options_option as oo on oo.id = ov.option_id wher

我对django中的ORM查询相当陌生。我使用下面的sql从数据库中获取数据

Select * from  subnets_subnet as sb
left join subnets_subnetoption as sbo on sb.id = sbo.subnet_id 
left join options_value as ov on ov.id=sbo.value_id
left join options_option as oo on oo.id = ov.option_id
where oo.name='Customer'
如何连接三个多表,即使其中一个来自另一个django应用程序?ieoptions\u valueoptions\u option来自另一个应用程序

class Subnet(models.Model):
    parent = models.ForeignKey('self', blank=True, null=True, editable=False)
    base_address = MyGenericIPAddressField(protocol='IPv4', db_index=True)
    creation_date = models.DateTimeField(auto_now_add=True, editable=False)
    modification_date = models.DateTimeField(auto_now=True, editable=False)

    zone = models.ForeignKey('zones.SecurityZone')
    dns_authority = models.ForeignKey('dns.DnsAuthority')


class SubnetOption(models.Model):
    subnet = models.ForeignKey('Subnet')
    value = models.ForeignKey('options.Value')

class Option(models.Model):
    name = models.CharField(max_length=40)
    required = models.BooleanField(default=False)
    scope = models.ForeignKey('Scope')


class Value(models.Model):
    content = models.CharField(max_length=60)
    comment = models.CharField(max_length=80, blank=True, null=True)
    option = models.ForeignKey('Option')

“至少要提到django模特儿。”Hsandher说。添加了模型结构您是否已尝试在
子网
应用程序中导入
选项
模型并添加适当的外键约束?@themanatuf。是的,我做了。然后使用select_相关查询。“但不工作,至少要提一下django模特儿。”Hsandher说。添加了模型结构您是否已尝试在
子网
应用程序中导入
选项
模型并添加适当的外键约束?@themanatuf。是的,我做了。然后使用select_相关查询。但不起作用