class Orders(db.Model): __tablename__ = 'orders' userId = db.Column(db.Integer, db.ForeignKey('users.id')) ISBN = db.Column(db.String(13), db.ForeignKey('books.ISBN'), nullable=True) id = db.Column(db.Integer, primary_key=True) quantity = db.Column(db.Integer)
class BlogPost(db.Model): # Setup the relationship to the User table # Notice the same .relationship was used in the users table. users = db.relationship(User) ################################################################### # [DATABASE(index), user_id(shared with user), date, title, text] ################################################################## # Model for the Blog Posts on Website # Individual ID for each post id = db.Column(db.Integer, primary_key=True) # Notice how we connect the BlogPost to a particular author user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) # ID of the user'users.id' # Date of the post, uses Date API date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) # Title of the post title = db.Column(db.String(140), nullable=False) # Text of the post text = db.Column(db.Text, nullable=False) rating = db.Column(db.String(140)) true_private = db.Column(db.String(140)) book_isbn = db.Column(db.String(140)) # Creating an instance of a blog post def __init__(self, title, text, user_id, rating, true_private, book_isbn): self.title = title # Always done in python self.text = text self.user_id = user_id self.rating = rating self.true_private = true_private self.book_isbn = book_isbn def __repr__(self): # representation of each blog post return f"Post Id: {self.id} --- Date: {self.date} --- Title: {self.title} --- Rating: {self.rating}"
class Wishlist3(db.Model): __tablename__ = 'wishlists3' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.Text, nullable=False) user_id = db.Column(db.Integer, ForeignKey('users.id'), nullable=False) ISBN = db.Column(db.String(13), db.ForeignKey('books.ISBN'), nullable=False) #books = db.Column(db.String, ForeignKey('books.ISBN'), nullable=True) def __init__(self, title, user_id, ISBN): self.title = title self.user_id = user_id self.ISBN = ISBN
class SavedItems(db.Model): __tablename__ = 'saved_items' userId = db.Column(db.Integer, db.ForeignKey('users.id')) ISBN = db.Column(db.String(13), db.ForeignKey('books.ISBN'), nullable=True) id = db.Column(db.Integer, primary_key=True)