-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
68 lines (49 loc) · 1.94 KB
/
models.py
File metadata and controls
68 lines (49 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from sqlalchemy import *
from sqlalchemy_utils import *
from sqlalchemy.orm import declarative_base
db = create_engine("sqlite:///banco.db")
Base = declarative_base()
class Usuario(Base):
__tablename__ = "usuarios"
id = Column("id", Integer, primary_key=True, autoincrement=True)
nome = Column("nome", String)
email = Column("email", String, nullable=False)
senha = Column("senha", String)
ativo = Column("ativo", Boolean)
admin = Column("admin", Boolean, default=False)
def __init__(self, nome, email, senha, ativo=True, admin=False):
self.nome = nome
self.email = email
self.senha = senha
self.ativo = ativo
self.admin = admin
class Pedido(Base):
__tablename__="pedidos"
STATUS_PEDIDOS = (
("PENDENTE", "PENDENTE"),
("CANCELADO", "CANCELADO"),
("FINALIZADO", "FINALIZADO")
)
id = Column("id", Integer, primary_key=True, autoincrement=True)
status = Column("status", String) # pendente , preparação e finalizado
usuario = Column("usuario", Integer, ForeignKey("usuarios.id"))
preco = Column("preco", Float)
# itens
def __init__(self, usuario,status="PENDENTE", preco=0):
self.usuario = usuario
self.preco = preco
self.status = status
class ItemPedido(Base):
__tablename__="itens_pedidos"
id = Column("id", Integer, primary_key=True, autoincrement=True)
quantidade = Column("quantidade", Integer)
sabor = Column("sabor", String)
tamanho = Column("tamanho", String)
preco_unitario = Column("preco_unitario", Float)
pedido = Column("pedido", ForeignKey("pedidos.id"))
def __init__(self, quantidade, sabor, tamanho, preco_unitario, pedido):
self.quantidade = quantidade
self.sabor = sabor
self. tamanho = tamanho
self.preco_unitario = preco_unitario
self.pedido = pedido