class User(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), unique=True, nullable=False) password = db.Column(db.String(128)) def __repr__(self): return '<User %r>' % self.username def set_password(self, password): self.password = generate_password_hash(password) db.session.commit() def check_password(self, password): return check_password_hash(self.password, password) def get_id(self): return str(self.id) @property def is_active(self): return True @property def is_anonymous(self): return False @property def is_authenticated(self): return True
class User(db.Model, UserMixin): __tablename__ = "users" id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) password = db.Column(db.String(60), nullable=False) reviews = db.relationship("Review", backref="user", lazy=True)
class Book(db.Model, UserMixin): __tablename__ = "books" id = db.Column(db.Integer, primary_key=True) isbn = db.Column(db.String(120), nullable=False) title = db.Column(db.String(120), nullable=False) author = db.Column(db.String(120), nullable=False) year = db.Column(db.String(120), ) reviews = db.relationship("Review", backref="book", lazy=True)
class Book(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(256), nullable=False) img = db.Column(db.String(256)) description = db.Column(db.Text) created_at = db.Column(db.DateTime, default=datetime.datetime.now) def __repr__(self): return '<Book %r>' % self.title
class Review(db.Model): __tablename__ = "reviews" id = db.Column(db.Integer, primary_key=True) rate = db.Column(db.Integer, nullable=False) body = db.Column(db.String(500), nullable=False) review_time = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) book_id = db.Column(db.Integer, db.ForeignKey('books.id'), nullable=False)