class OrderList(db.Model): tid = db.Column(db.Integer,primary_key=True) book_ISBN = db.Column(db.String(100),db.ForeignKey('books.bid')) quantity = db.Column(db.Integer,nullable=False) user_id=db.Column(db.Integer,db.ForeignKey('user.id')) total_price = db.Column(db.Integer,nullable=False) selling_date = db.Column(db.DateTime, nullable = False)
class Ratings(db.Model): rid = db.Column(db.Integer,primary_key=True) rating = db.Column(db.Integer,default=0) user_id = db.Column(db.Integer,db.ForeignKey('user.id')) book_id = db.Column(db.String(100),db.ForeignKey('books.ISBN')) def __repr__(self): return f"Ratings('{self.book_id}','{self.user_id}','{self.rating}')"
class offer(db.Model): offerid = db.Column(db.Integer,primary_key=True) user_id = db.Column(db.Integer,db.ForeignKey('user.id')) discount=db.Column(db.Integer,default=0,nullable=False) def get_json(self): return { self.user_id:self.discount}
class User(db.Model, UserMixin, CRUDMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(30), unique = False, index = True) email = db.Column(db.String(100), unique = True) password_hash = db.Column(db.String(128)) role_id = db.Column(db.Integer, db.ForeignKey('role.id')) number = db.Column(db.String(30)) def __init__(self, username, email, password, number): self.username = username self.email = email self.password = password self.number = number if self.email == admin_email: self.role_id = admin_permission else: self.role_id = user_permission def __repr__(self): return '<User %r>' % self.username def is_administrator(self): if self.role_id == admin_permission: return True @property def password(self): raise AttributeError('password is not a readable attribute') @password.setter def password(self, password): self.password_hash = generate_password_hash(password) def verify_password(self, password): return check_password_hash(self.password_hash, password)
class Association(db.Model, CRUDMixin): books = db.Column(db.String(30), db.ForeignKey('book.id', ondelete='cascade'), primary_key=True) authors = db.Column(db.String(30), db.ForeignKey('author.id', ondelete='cascade'), primary_key=True)