Python Peewee AttributeError - When I consult with more than one join

0

I am trying to make a query with ORM Peewee with a connection to an existing database . Specifically I need to relate three tables with joins but I get the following error:

(work) C: \ Users \ eguzman \ Documents \ python-work \ asterisk-insert-reminder> python script.py Traceback (most recent call last): File "script.py", line 41, in row.ageagendas.CODIGO, row.ageagendas.PER_ID, row.stkpersonas.DOCUMENTO)) AttributeError : 'AgeCitas' object has no attribute 'stkpersonas'

Probably the problem is related to the declaration of the fields in the model, but as I am not an expert in Peewee I do not detect the problem, I leave the code, thanks ...

The code: script.py

import peewee as pw
from classes.model import MySqlDbModel, AgeCitas, AgeAgendas, StkPersonas


class SelectCitasToRemind(MySqlDbModel):

    @staticmethod
    def selectCitasToRemind():
        cit = AgeCitas.alias()
        age = AgeAgendas.alias()
        per = StkPersonas.alias()
        query = (cit.select(
            cit.CIT_ID, cit.AGE_ID, cit.FECHAHORA,
            age.AGE_ID, age.CODIGO, age.CEN_ID, age.PER_ID,
            per.PER_ID, per.DOCUMENTO, per.NOMBRE)
            .join(age, pw.JOIN.LEFT_OUTER, on=(cit.AGE_ID == age.AGE_ID))
            .join(per, pw.JOIN.LEFT_OUTER, on=(age.PER_ID == per.PER_ID))
            .where((cit.CIT_ID.is_null(False))
                   & (cit.PAC_ID.is_null(False))
                   )
            .limit(10)
        )
        return query


 query = SelectCitasToRemind.selectCitasToRemind()

 for row in query:
     print("{} | {} | {} | {} | {} | {}".format(
        row.CIT_ID, row.AGE_ID, row.FECHAHORA,
        row.ageagendas.CODIGO, row.ageagendas.PER_ID, row.stkpersonas.DOCUMENTO))

The code: classes / model.py

import peewee as pw


# Conection to mydbname database
dbn = 'mydbname'
user = 'myusername'
pwd = '******'
host = 'localhost'
prt = 3306

db = pw.MySQLDatabase(dbn, user=user,
                  password=pwd,  host=host, port=prt)


class MySqlDbModel(pw.Model):
    class Meta:
        database = db


class AgeCitas(MySqlDbModel):
    CIT_ID = pw.BigIntegerField()
    AGE_ID = pw.BigIntegerField()
    FECHAHORA = pw.DateTimeField()
    ACT_ID = pw.BigIntegerField()
    PAC_ID = pw.BigIntegerField()
    ASIGNADA = pw.CharField()
    IND_ID = pw.BigIntegerField()
    ACUDIO = pw.DoubleField()
    ORDEN = pw.DoubleField()

class Meta:
    table_name = 'AGE_CITAS'


class AgeAgendas(MySqlDbModel):
    AGE_ID = pw.DecimalField()
    CODIGO = pw.CharField()
    CEN_ID = pw.DecimalField()
    PER_ID = pw.DecimalField()
    NPR_ID = pw.DecimalField()
    DESCRIPCION = pw.CharField()
    COLOR = pw.CharField()

class Meta:
    table_name = 'AGE_AGENDAS'


class StkPersonas(MySqlDbModel):
    PER_ID = pw.BigIntegerField()
    DOCUMENTO = pw.CharField()
    NOMBRE = pw.CharField()
    APELLIDO1 = pw.CharField()
    APELLIDO2 = pw.CharField()
    FECHA_ALTA = pw.DateTimeField()
    FECHA_BAJA = pw.DateTimeField()
    EMAIL = pw.CharField()
    TELEFONO1 = pw.CharField()
    TELEFONO2 = pw.CharField()
    TELEFONO3 = pw.CharField()
    TELEFONO4 = pw.CharField()
    SEXO = pw.CharField()
    NACIMIENTO = pw.DateTimeField()
    ES_PACIENTE = pw.CharField()
    ES_PROFESIONAL = pw.CharField()

class Meta:
    table_name = 'STK_PERSONAS'
    
asked by Exequiel Guzmán 17.05.2018 в 23:28
source

0 answers