This repository has been archived by the owner on Feb 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
53 lines (46 loc) · 1.55 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 flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class Movie(db.Model):
__tablename__ = 'movies'
id = db.Column(db.Integer, primary_key=True)
movie_id = db.Column(db.Integer)
image = db.Column(db.String(500))
title = db.Column(db.String(200))
release_year = db.Column(db.String(4))
duration = db.Column(db.String(200))
genre = db.Column(db.String(200))
description = db.Column(db.Text())
# constructor
def __init__(self, movie_id, image, title, release_year, duration, genre, description):
self.movie_id = movie_id
self.image = image
self.title = title
self.release_year = release_year
self.duration = duration
self.genre = genre
self.description = description
def save(data):
db.session.add(data)
db.session.commit()
movies_list = Movie.get_all()
results = []
for movie in movies_list:
obj = {
'id': movie.id,
'movie_id': movie.movie_id,
'image': movie.image,
'title': movie.title,
'release_year': movie.release_year,
'duration': movie.duration,
'genre': movie.genre,
'description': movie.description
}
results.append(obj)
return results
@staticmethod
def get_all():
return Movie.query.all()
def delete(id):
movie = Movie.query.filter(Movie.movie_id == id).first()
db.session.delete(movie)
db.session.commit()