-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.py
53 lines (37 loc) · 1.69 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
from sqlalchemy import Float, Column, ForeignKey, Integer, String, Boolean
from sqlalchemy.orm import relationship
from database import Base
class User(Base):
__tablename__ = "Users"
id = Column(Integer, primary_key=True, index=True)
email = Column(String, unique=True, index=True, nullable=False)
password = Column(String, nullable=False)
name = Column(String, nullable=False)
surname = Column(String, nullable=False)
phone = Column(String)
address = Column(String)
is_admin = Column(Boolean, default=False)
purchases = relationship("Purchase", back_populates="user")
class Purchase(Base):
__tablename__ = "Purchases"
id = Column(Integer, primary_key=True, index=True)
user_id = Column(Integer, ForeignKey("Users.id"))
start_date = Column(String, nullable=False)
expiry_date = Column(String, nullable=False)
cost = Column(Integer, nullable=False)
user = relationship("User", back_populates="purchases")
movie_list = relationship("Movie", secondary="MoviesLists", back_populates="purchase")
class MovieList(Base):
__tablename__ = "MoviesLists"
purchase_id = Column(Integer, ForeignKey("Purchases.id"), primary_key=True)
movie_id = Column(Integer, ForeignKey("Movies.id"), primary_key=True)
class Movie(Base):
__tablename__ = "Movies"
id = Column(Integer, primary_key=True)
title = Column(String, unique=True, nullable=False)
director = Column(String)
release_year = Column(Integer)
genre = Column(String, nullable=False)
rating = Column(Float)
cost_per_day = Column(Integer, nullable=False)
purchase = relationship("Purchase", secondary="MoviesLists", back_populates="movie_list", uselist=False)