Мне нужно левое внешнее соединение трех таблиц

Я хочу сделать 'Left outer join' на основе 'PMP_MODEL', как показано в SQL запросе ниже.

SELECT  *
            FROM  PMP_MODEL A
            LEFT OUTER JOIN PMP_REPAIR_HISTORY B ON A.PMP_MANU_NUM = B.PMP_MANU_NUM
            LEFT OUTER JOIN SITE_INFO C ON A.PMP_MANU_NUM = C.PMP_MANU_NUM
            LEFT OUTER JOIN SITE_DETAIL_INFO D ON A.PMP_MANU_NUM = D.PMP_MANU_NUM
            WHERE A.PMP_MANU_NUM = ?

Django Model.py

class PmpModel(models.Model):
    pmp_manu_num = models.CharField(db_column='PMP_MANU_NUM', primary_key=True, max_length=50, db_collation='utf8_general_ci')  # Field name made lowercase.
    pmp_model_nm = models.CharField(db_column='PMP_MODEL_NM', max_length=50, db_collation='utf8_general_ci', blank=True, null=True)  # Field name made lowercase.
    #~~~ many column


class PmpRepairHistory(models.Model):
    pmp_num = models.ForeignKey(PmpModel , on_delete = models.SET_NULL, null=True, db_column='pmp_manu_num' ,related_name='pmp_history')
    pmp_manu_num = models.CharField(db_column='PMP_MANU_NUM', primary_key=True, max_length=50, db_collation='utf8_general_ci')  # Field name made lowercase.
    #~~~ many column
   


class SiteDetailInfo(models.Model):
    pmp_manu_num = models.CharField(db_column='PMP_MANU_NUM', max_length=50, db_collation='utf8_general_ci')  # Field name made lowercase.
    #~~~ many column


class SiteInfo(models.Model):
    pmp_manu_num = models.CharField(db_column='PMP_MANU_NUM', max_length=50, db_collation='utf8_general_ci')  # Field name made lowercase.
    #~~~ many column
    

Я пробовал с 'select_related', но это не работает.

class PmpModelList(APIView):
    def get(self, request, format = None):
        pmpList = PmpModel.objects.select_related('pmp_manu_num')

        serialize = PmpModelSerializer(pmpList, many = True)
        return Response(serialize.data)
Вернуться на верх