class TarefaModel(db.Model): __tablename__ = "tarefa" id = db.Column(db.Integer, primary_key=True, autoincrement=True, nullable=False) titulo = db.Column(db.String(50), nullable=False) descricao = db.Column(db.String(100), nullable=False) data_expiracao = db.Column(db.Date, nullable=False) projeto_id = db.Column(db.Integer, db.ForeignKey("projeto.id")) projeto = db.relationship("ProjetoModel", backref=db.backref("tarefas", lazy="dynamic")) @classmethod def find_all(cls) -> List["TarefaModel"]: return cls.query.all() @classmethod def find_by_id(cls, _id: int) -> "TarefaModel": return cls.query.filter_by(id=_id).first() def save_to_db(self) -> None: db.session.add(self) db.session.commit() def delete_from_db(self) -> None: db.session.delete(self) db.session.commit()
class Tecnologia(db.Model): __tablename__ = "tecnologia" id = db.Column(db.Integer, primary_key=True) nome = db.Column(db.String(30), nullable=False) tipo = db.Column(db.String(30), nullable=False) programadores = db.relationship("Programador", secondary=ProgramadorTecnologia, back_populates="tecnologias")
class ProjetoModel(db.Model): __tablename__ = "projeto" id = db.Column(db.Integer, primary_key=True, autoincrement=True, nullable=False) nome = db.Column(db.String(50), nullable=False) descricao = db.Column(db.String(100), nullable=False) @classmethod def find_all(cls) -> List["ProjetoModel"]: return cls.query.all() @classmethod def find_by_id(cls, _id: int) -> "ProjetoModel": return cls.query.filter_by(id=_id).first() def save_to_db(self) -> None: db.session.add(self) db.session.commit() def delete_from_db(self) -> None: db.session.delete(self) db.session.commit()
class Programador(db.Model): __tablename__ = "programador" id = db.Column(db.Integer, primary_key=True) nome = db.Column(db.String(30), nullable=False) experiencia = db.Column(db.Integer, nullable=False) tecnologias = db.relationship("Tecnologia", secondary=ProgramadorTecnologia, back_populates="programadores")
class Usuario(db.Model): __tablename__ = 'usuarios' id = db.Column(db.Integer, primary_key=True, autoincrement=True) usuario = db.Column(db.String(128), nullable=False) email = db.Column(db.String(128), nullable=False) ativo = db.Column(db.Boolean, default=True, nullable=False) data_criacao = db.Column(db.DateTime, default=func.now(), nullable=False) def __init__(self, usuario, email): self.usuario = usuario self.email = email
class UsuarioModel(db.Model): __tablename__ = "usuario" id = db.Column(db.Integer, primary_key=True) usuario = db.Column(db.String(80), nullable=False, unique=True) senha = db.Column(db.String(80), nullable=False) @classmethod def find_by_usuario(cls, usuario: str) -> "UsuarioModel": return cls.query.filter_by(usuario=usuario).first() @classmethod def find_by_id(cls, _id: int) -> "UsuarioModel": return cls.query.filter_by(id=_id).first() def save_to_db(self) -> None: db.session.add(self) db.session.commit() def delete_from_db(self) -> None: db.session.delete(self) db.session.commit()
from sistema import app, db ProgramadorTecnologia = db.Table("programadorTecnologia", db.Column('id_programador', db.Integer, db.ForeignKey('programador.id')), db.Column('id_tecnologia', db.Integer, db.ForeignKey('tecnologia.id'))) class Tecnologia(db.Model): __tablename__ = "tecnologia" id = db.Column(db.Integer, primary_key=True) nome = db.Column(db.String(30), nullable=False) tipo = db.Column(db.String(30), nullable=False) programadores = db.relationship("Programador", secondary=ProgramadorTecnologia, back_populates="tecnologias")
class FuncionarioModel(db.Model): __tablename__ = "funcionario" id = db.Column(db.Integer, primary_key=True, autoincrement=True, nullable=False) nome = db.Column(db.String(50), nullable=False) cpf = db.Column(db.String(11), nullable=False) rg = db.Column(db.String(20), nullable=False) data_nascimento = db.Column(db.Date, nullable=False) email = db.Column(db.String(50), nullable=False) telefone_celular = db.Column(db.String(12), nullable=False) endereco_rua = db.Column(db.String(512), nullable=False) endereco_bairro = db.Column(db.String(50), nullable=False) endereco_numero = db.Column(db.Integer, nullable=False) endereco_cidade = db.Column(db.String(25), nullable=False) endereco_estado = db.Column(db.String(50), nullable=False) endereco_complemento = db.Column(db.String(50), nullable=False) endereco_cep = db.Column(db.Integer, nullable=False) tarefa_id = db.Column(db.Integer, db.ForeignKey("tarefa.id")) tarefa = db.relationship("TarefaModel", backref=db.backref("funcionarios", lazy="dynamic")) @classmethod def find_all(cls) -> List["FuncionarioModel"]: return cls.query.all() @classmethod def find_by_id(cls, _id: int) -> "FuncionarioModel": return cls.query.filter_by(id=_id).first() def save_to_db(self) -> None: db.session.add(self) db.session.commit() def delete_from_db(self) -> None: db.session.delete(self) db.session.commit()