-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
49 lines (38 loc) · 1.43 KB
/
models.py
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
from database import Base
from sqlalchemy import Column, Integer, String, Boolean, Text, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy_utils.types import ChoiceType
class User(Base):
__tablename__ = "user"
id = Column(Integer, primary_key=True)
username = Column(String(25), unique=True)
email = Column(String(50), unique=True)
password = Column(Text, nullable=True)
is_staff = Column(Boolean, default=False)
is_active = Column(Boolean, default=False)
orders = relationship("Order", back_populates="user")
def __repr__(self):
return f"<User {self.username}>"
class Order(Base):
ORDER_STATUSES = (
("PENDING", "pending"),
("IN-TRANSIT","in-transit"),
("DELIVERED", "delivered"),
)
PIZZA_SIZES = (
("SMALL", "small"),
("MEDIUM", "medium"),
("LARGE", "large"),
("EXTRA-LARGE", "extra-large"),
)
__tablename__ = "orders"
id = Column(Integer, primary_key=True)
quantity = Column(Integer, nullable=False)
order_status = Column(ChoiceType(choices = ORDER_STATUSES), default="PENDING")
pizza_size = Column(ChoiceType(choices = PIZZA_SIZES), default="SMALL")
user_id = Column(Integer, ForeignKey("user.id"))
user = relationship("User", back_populates="orders")
def __repr__(self):
return f"<Order {self.id}>"
# name = Column(String(25), unique=True)
# price = Column(Integer)