This repository has been archived by the owner on May 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
57 lines (41 loc) · 1.85 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
50
51
52
53
54
55
56
57
import enum
from sqlalchemy import Column, String, ForeignKey, Date, Enum, Float, Boolean, Integer
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Household(Base):
__tablename__ = "household"
id = Column(Integer, primary_key=True, nullable=False)
name = Column(String(256), nullable=False)
utilities = relationship("Utility", backref="household")
users = relationship("User", backref="household")
rooms = relationship("Room", backref="household")
class Utility(Base):
__tablename__ = "utility"
id = Column(Integer, primary_key=True, nullable=False)
household_id = Column(Integer, ForeignKey('household.id'))
name = Column(String(length=256), nullable=False)
cost = Column(Float, nullable=False, default=0)
due_date = Column(Date, nullable=False)
user_id = Column(Integer, ForeignKey('user.id'))
class User(Base):
__tablename__ = "user"
id = Column(Integer, primary_key=True, nullable=False)
household_id = Column(Integer, ForeignKey('household.id'))
room_id = Column(Integer, ForeignKey("room.id"))
in_charge_of = relationship("Utility", backref="user_in_charge")
name = Column(String(length=256), nullable=False)
email = Column(String(length=256), nullable=False)
password = Column(String(length=256), nullable=False)
leader = Column(Boolean, default=False, nullable=False)
venmo = Column(String(length=256), nullable=False)
class RoomType(enum.Enum):
bed_room = 0
common_room = 1
class Room(Base):
__tablename__ = "room"
id = Column(Integer, primary_key=True, nullable=False)
household_id = Column(Integer, ForeignKey('household.id'))
users = relationship("User", backref="rooms")
type = Column(Enum(RoomType), nullable=False)
size = Column(Float, nullable=False, default=0)