-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodels.py
152 lines (90 loc) · 3.91 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
from datetime import datetime
from sqlalchemy.dialects.postgresql import UUID
import uuid
from traitlets import default
from database import Base,engine,SessionLocal
from sqlalchemy import Column, ForeignKey,String,DateTime,Integer,Table,Float
from sqlalchemy.orm import relationship
class Watched(Base):
__tablename__="watched"
watch_id=Column(UUID(as_uuid=True),primary_key=True,default=uuid.uuid4)
user_id=Column(UUID(as_uuid=True),ForeignKey('user.user_id'))
movie_id=Column(UUID(as_uuid=True),ForeignKey('movie.movie_id'))
class User(Base):
__tablename__="user"
user_id=Column(UUID(as_uuid=True),default=uuid.uuid4,primary_key=True)
name=Column(String,nullable=False)
email=Column(String,nullable=False)
password =Column(String,nullable=False)
created_at=Column(DateTime,default=datetime.utcnow,nullable=False)
ratings=relationship("Rating",backref="user_rating")
subscription= relationship("Subscription", backref="user_sub")
class Subscription(Base):
__tablename__='subscription'
id=Column(UUID(as_uuid=True),default=uuid.uuid4,primary_key=True)
user_id=Column(UUID(as_uuid=True),ForeignKey('user.user_id'))
start_timestamp = Column(DateTime(timezone=True),default=datetime.utcnow)
end_timestamp = Column(DateTime(timezone=True),nullable=False)
class Rating(Base):
__tablename__="rating"
rating_id=Column(UUID(as_uuid=True),default=uuid.uuid4,primary_key=True)
user_id= Column(UUID(as_uuid=True),ForeignKey("user.user_id"))
movie_id=Column(UUID(as_uuid=True),ForeignKey("movie.movie_id"))
stars=Column(Float,nullable=False)
comments=Column(String(3000))
created_timestamp = Column(DateTime(timezone=True),default=datetime.utcnow,nullable=False)
junction_table = Table('movie_genre', Base.metadata,
Column('movie_id', UUID(as_uuid=True), ForeignKey('movie.movie_id')),
Column('genre_id', UUID(as_uuid=True), ForeignKey('genre.genre_id')),
)
class Movie(Base):
__tablename__="movie"
movie_id=Column(UUID(as_uuid=True),default=uuid.uuid4,primary_key=True)
title=Column(String,nullable=False)
description =Column(String(300))
language=Column(String(30),nullable=False)
release_date=Column(DateTime(timezone=True),nullable=False)
director=Column(String(30),nullable=False)
ratings=relationship("Rating",backref="movie")
genres=relationship('Genre',secondary=junction_table,backref="movies")
class Genre(Base):
__tablename__="genre"
genre_id=Column(UUID(as_uuid=True),default=uuid.uuid4,primary_key=True)
genre_name=Column(String(50),nullable=False)
# class Action(Base):
# __tablename__="action"
# id = Column(Integer,primary_key=True)
# movie_name=Column(String,nullable=False)
# genre=Column(String,nullable=False)
# description =Column(String,nullable=False)
# class Config:
# orm_mode=True
# class Romance(Base):
# __tablename__="romance"
# id = Column(Integer,primary_key=True)
# movie_name=Column(String,nullable=False)
# genre=Column(String,nullable=False)
# description =Column(String,nullable=False)
# class Config:
# orm_mode=True
# class Comedy(Base):
# __tablename__="comedy"
# id = Column(Integer,primary_key=True)
# movie_name=Column(String,nullable=False)
# genre=Column(String,nullable=False)
# description =Column(String,nullable=False)
# class Config:
# orm_mode=True
# class Thriller(Base):
# __tablename__="thriller"
# id = Column(Integer,primary_key=True)
# movie_name=Column(String,nullable=False)
# genre=Column(String,nullable=False)
# description =Column(String,nullable=False)
# class Config:
# orm_mode=True
# data = User(name='arun',email='[email protected]',password="123")
# db=SessionLocal()
# db.add(data)
# db.commit()
# db.refresh(data)