Django Python Обработка ссылок на таблицы базы данных

В настоящее время я пытаюсь создать пробный баланс с данными, которые поступают из 3 таблиц в моей базе данных Sage 200 MSSQL, данные связаны между 4 строками в таблицах.

Например: [PostGL].[AccountLink] ссылается на [Accounts].[AccountLink] & [Accounts].[iAccountType] ссылается на [GLAccountTypes].[idGLAccountType]

Мне нужно найти способ связать эти 3 таблицы соответствующими ссылками и получить следующие данные для печати в пробный баланс:

[PostGL] = Дебет & Кредит

[GLAccountTypes] = Описание

[Счета] = Номер счета

Вот мой текущий код:

Views.py:

susAcc = list('161','162','163','164','165','166','167','168','112')

    def home(request):
    
        return render(request , 'main/home.html')
    
    def Kyletrb(request):
        postGL = ("SELECT AccountLink , Debit , Credit FROM [Kyle].[dbo].[PostGl] WHERE AccountLink <> ?")
    
        cursor = cnxn.cursor();
        cursor.execute(postGL, susAcc);
        arrPostGL = [tup[0] for tup in cursor.fetchall()]
    
        accTypes = "SELECT idGLAccountType, cAccountTypeDescription FROM [Kyle].[dbo].[_etblGLAccountTypes]"
    
        cursor = cnxn.cursor();
        cursor.execute(accTypes);
        arrAccTypes = [tup[0] for tup in cursor.fetchall()]
    
        accounts = "SELECT AccountLink ,Master_Sub_Account , iAccountType FROM [Kyle].[dbo].[Accounts]"
    
        cursor = cnxn.cursor();
        cursor.execute(accounts);
        arrAccounts = [tup[0] for tup in cursor.fetchall()]
    
        return render(request , 'main/Kyletrb.html' )

Kyletrb.html:

Вернуться на верх