-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModels.py
More file actions
executable file
·39 lines (33 loc) · 1.39 KB
/
Copy pathModels.py
File metadata and controls
executable file
·39 lines (33 loc) · 1.39 KB
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
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
db = SQLAlchemy()
class Book(db.Model):
__tablename__ = 'books'
isbn = db.Column(db.String, primary_key = True)
title = db.Column(db.String, nullable=False)
author = db.Column(db.String, nullable=False)
year= db.Column(db.Integer, nullable=False)
class Account(db.Model):
__tablename__ = 'account'
username = db.Column(db.String, primary_key = True)
password = db.Column(db.String, nullable=False)
created_on = db.Column(db.DateTime, nullable=False)
last_login= db.Column(db.DateTime, nullable=True)
def update_last_login(self):
self.last_login = str(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
class Bookreview(db.Model):
__tablename__ = 'bookreviews'
username = db.Column(db.String, db.ForeignKey("account.username"), nullable = False)
isbn = db.Column(db.String, db.ForeignKey("books.isbn"), nullable = False)
comment = db.Column(db.String, nullable = False)
stars = db.Column(db.Integer, nullable = False)
created_on = db.Column(db.DateTime, nullable = False)
db.PrimaryKeyConstraint(isbn,username)
def addReview(newReview):
try:
db.session.add(newReview)
db.session.commit()
return True
except:
db.session().rollback()
return False