models.py 1.78 KB
from sqlalchemy import Column, INTEGER, VARCHAR, ForeignKey, DATE
from sqlalchemy.orm import relationship

from database import ModelBase
from utils.models import Nacionalidad


class Sexo(ModelBase):
    __tablename__ = 'tb_sexo'

    id = Column('idSexo', INTEGER(), primary_key=True, nullable=False)
    nombre = Column('Descripcion', VARCHAR(length=17), nullable=False)
    abreviacion = Column('Mnemo', VARCHAR(length=1))

    def __str__(self):
        return f"{self.nombre}"

    def __repr__(self):
        return f"<Sexo: {self}>"


class Persona(ModelBase):
    __tablename__ = 'tb_personas'

    id = Column('idPersona', INTEGER(), primary_key=True, nullable=False)
    apellido = Column('Apellido', VARCHAR(length=100), nullable=False)
    nombres = Column('Nombres', VARCHAR(length=100), nullable=False)
    cuil = Column('CUIL', VARCHAR(length=20))
    documento = Column('Documento', INTEGER(), nullable=False)
    fecha_nacimiento = Column('FechaNacimiento', DATE(), nullable=False)
    domicilio = Column('Domicilio', VARCHAR(length=100))
    codigo_postal = Column('CodPostal', VARCHAR(length=20))
    telefono = Column('Telefono', VARCHAR(length=30))
    email = Column('Email', VARCHAR(length=50))

    es_discapacitado = Column('EsDiscapacitado', VARCHAR(length=1), nullable=False)
    vive = Column('Vive', VARCHAR(length=1))

    # Relaciones.
    sexo_id = Column('Sexo', INTEGER(), ForeignKey('tb_sexo.idSexo'), nullable=False)
    sexo = relationship('Sexo')

    nacionalidad_id = Column('Nacionalidad', INTEGER(), ForeignKey('tb_Nacionalidad.idNacionalidad'))
    nacionalidad = relationship(Nacionalidad)

    # TODO: Agregar TipoDocumento, LocalidadNac

    def __str__(self):
        return f"{self.apellido}, {self.nombres}"

    def __repr__(self):
        return f"<Persona {self}>"