class BookRating(db.Model): id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy book_id = db.Column(db.Integer, db.ForeignKey('book.id'), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) rating = db.Column(db.Integer, default=0)
class Review(db.Model): book_id = db.Column(db.String(25), db.ForeignKey('book.id'), primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True) username = db.Column(db.String(25), nullable=False) bookname = db.Column(db.String(50), nullable=False) timestamp = db.Column(db.DateTime, default=datetime.utcnow) review = db.Column(db.Text) rating = db.Column(db.Float) books = db.relationship("Book", back_populates="reviews") users = db.relationship("User", back_populates="reviews")
class Posts(db.Model): __tablename__ = "posts" id = db.Column(db.Integer, primary_key=True, nullable=False) userid = db.Column(db.Integer , db.ForeignKey("user.id") , nullable = False) title = db.Column(db.String(50) , default = 'My post') post = db.Column(db.Text, nullable=False) likes = db.Column(db.Integer, default=0) regdate = db.Column(db.DateTime ,nullable = False )
class Post(db.Model): __tablename__ = "post" id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(60), nullable=False) date_posted = db.Column(db.DateTime, nullable=False, default=datetime.now()) content = db.Column(db.Text, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __repr__(self): return f"Post('{self.title}','{self.date_posted}')"
class File(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(30), unique=True, nullable=False) upload_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) update_time = db.Column(db.DateTime, nullable=True) description = db.Column(db.String(100)) user_id = db.Column(db.String(50), db.ForeignKey('user.email'), nullable=False) def __repr__(self): return f"File('{self.name}', '{self.upload_date}')"
class LikedPosts(UserMixin, db.Model): __tablename__ = "liked_post" id = db.Column(db.Integer, primary_key=True, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False) post_id = db.Column(db.Integer, db.ForeignKey("posts.id"), nullable=False)