Converting LEFT OUTER JOIN query to Django orm queryset/query

后端 未结 2 1084
我寻月下人不归
我寻月下人不归 2021-02-10 00:19

Given PostgreSQL 9.2.10, Django 1.8, python 2.7.5 and the following models:

class restProdAPI(models.Model):
    rest_id = models.PositiveIntegerField(primary_ke         


        
2条回答
  •  有刺的猬
    2021-02-10 00:48

    I think this could be usefull for you! Effectively, you can use Q to construct your query. I try it the Django shell, I create some data and I did something like this:

    restProdAPI.objects.filter(Q(rest_host=s1.soap_host)|Q(rest_ip=s1.soap_ip))
    

    Where s1 is a soapProdAPI.

    This is all the code i whote, you can try it and to see if can help you

    from django.db.models import Q
    from core.models import restProdAPI, soapProdAPI
    
    s1 =  soapProdAPI.objects.get(soap_id=1)
    
    restProdAPI.objects.filter(Q(rest_id=s1.soap_id)|Q(rest_ip=s1.soap_ip))
    

提交回复
热议问题