class Tasks(db.Model): __tablename__ = 'tasks' id = db.Column(db.Integer, autoincrement=True, primary_key=True) descricao = db.Column(db.String(128), nullable=False) doneAt = db.Column(db.String(84), nullable=True) estimateAt = db.Column(db.String(84), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('users.id')) user = db.relationship("User", foreign_keys=user_id) def __init__(self, descricao, doneAt, estimateAt, user_id): self.descricao = descricao self.doneAt = doneAt self.estimateAt = estimateAt self.user_id = user_id def __repr__(self): return f"< demanda : {self.descricao}>"
class Usuario(UserMixin, db.Model): __tablename__ = 'usuario' id = db.Column(db.Integer, autoincrement=True, primary_key=True) nome = db.Column(db.String(100), nullable=False) email = db.Column(db.String(100), nullable=False) senha = db.Column(db.String(100), nullable=False) endereco = db.Column(db.String(100), nullable=False) cpf = db.Column(db.String(11), nullable=False, unique=True) data_nasc = db.Column(db.Date, nullable=False) email_verificado = db.Column(db.Integer, nullable=False, default=0) cargo = db.Column(db.String(100), default='cliente') comprador_vendas = db.relationship('Venda', backref='comprador', lazy='select') @staticmethod def salvar(usuario): try: if usuario.id: db.session.merge(usuario) else: db.session.add(usuario) db.session.commit() return True except exc.SQLAlchemyError: return False @staticmethod def excluir(id): try: usuario = Usuario.query.get(id) db.session.delete(usuario) db.session.commit() return True except exc.SQLAlchemyError: return False