-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
44 lines (38 loc) · 1.68 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
from app import db
from flask_login import UserMixin
from werkzeug.security import generate_password_hash, check_password_hash
class Books(db.Model):
__tablename__ = 'books'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
reviews = db.relationship('Reviews', backref='book', lazy=True)
title = db.Column(db.String(100), nullable=False)
isbn = db.Column(db.String(20))
year = db.Column(db.Integer)
author = db.Column(db.String(100))
num_rating = db.Column(db.Integer, default=0)
avg_rating = db.Column(db.Float, default=0)
class User(UserMixin, db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(100), nullable=False, unique=False)
email = db.Column(db.String(40), unique=True, nullable=False)
password = db.Column(db.String(200), primary_key=False,
unique=False, nullable=False)
def set_password(self, password):
self.password = generate_password_hash(password, method='sha256')
def check_password(self, password):
return check_password_hash(self.password, password)
class Reviews(db.Model):
__tablename__ = 'reviews'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
text = db.Column(db.Text())
rating = db.Column(db.Integer)
bookid = db.Column(db.ForeignKey('books.id'), nullable=False)
class GoogleUser(UserMixin, db.Model):
__tablename__ = 'google_users'
id = db.Column(db.Integer, primary_key=True,
autoincrement=True)
userid = db.Column(db.Text())
name = db.Column(db.String(100))
email = db.Column(db.String(100))
#profile_pic = db.Column(db.Text())