class Book(db.Model): id = db.Column(db.Integer, primary_key=True) isbn = db.Column(db.String(50)) author = db.Column(db.String(50)) title = db.Column(db.String(50)) year = db.Column(db.Integer) reviews=db.relationship('Review', backref='read', lazy=True)
class Base(db.Model): __abstract__ = True id = db.Column('id', db.Integer, primary_key=True, index=True) created_at = db.Column('created_at', db.DateTime(timezone=True), default=db.func.current_timestamp()) updated_at = db.Column('updated_at', db.DateTime(timezone=True), default=db.func.current_timestamp(), onupdate=db.func.current_timestamp()) def save(self): db.session.add(self) db.session.commit() db.session.flush() @staticmethod def insert(obj): db.session.add(obj) db.session.commit() db.session.flush() @staticmethod def update_db(): db.session.commit() db.session.flush() @classmethod def merge(cls, obj): db.session.merge(obj) db.session.commit()
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(20), unique=True, nullable=False) password = db.Column(db.String, nullable=False) email = db.Column(db.String(40), unique=True, nullable=False) reviews = db.relationship("Review", backref="author", lazy=True) def __repr__(self): return f"User({self.name}, {self.email})"
class Book(db.Model): id = db.Column(db.Integer, primary_key=True) isbn = db.Column(db.String, nullable=False) title = db.Column(db.String, nullable=False) author = db.Column(db.String, nullable=False) year = db.Column(db.Integer, nullable=False) reviews = db.relationship("Review", backref="book", lazy=True) def __repr__(self): return f"Book({self.isbn}, {self.title}, {self.author}, {self.year})"
class Book(Base): __tablename__ = 'book' title = db.Column(db.String, nullable=False) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def __repr__(self): return '<title %r>' % self.title
class Author(Base): __tablename__ = 'author' name = db.Column(db.String, nullable=False) books = db.relationship("Book", secondary=association_table, backref="book") def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def __repr__(self): return '<name %r>' % self.name
class Review(db.Model): id = db.Column(db.Integer, primary_key=True) text = db.Column(db.String, nullable=False) rating = db.Column(db.String, nullable=False) date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) user = db.relationship(User, lazy="joined", innerjoin=True) book_id = db.Column(db.Integer, db.ForeignKey('book.id'), nullable=False)
class Book(db.Model): id = db.Column(db.Integer, primary_key=True) author = db.Column(db.String(128)) title = db.Column(db.String(256)) publisher = db.Column(db.String(128)) pub_location = db.Column(db.String(128)) pub_date = db.Column(db.Integer) other = db.Column(db.String(256)) note = db.Column(db.TEXT) #This class will need a bunch of exception handling around dealing with ambiguous diels entry def __init__(self, author, title, publisher, location, date): self.author = author self.title = title self.publisher = publisher self.pub_location = location self.pub_date = date
class Review(db.Model): id = db.Column(db.Integer, primary_key=True) review= db.Column(db.Integer, nullable=False) book_id=db.Column(db.Integer, db.ForeignKey('book.id'), nullable=False) user_id=db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) comment=db.Column(db.String(), nullable=False)
class User(db.Model, UserMixin): 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='writer', lazy=True)
class Book(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.Text, nullable=False) author = db.Column(db.Text, nullable=False) image_file = db.Column(db.String(20)) date_started = db.Column(db.DateTime) date_completed = db.Column(db.DateTime) is_fiction = db.Column(db.Boolean, nullable=False) genre = db.Column(db.String(50), nullable=False) star_rating = db.Column(db.Integer, nullable=False) is_must_read = db.Column(db.Boolean, nullable=False) other_notes = db.Column(db.Text) def __repre__(self): return f'Title: {self.title}, By: {self.author}'
# -*- coding: utf-8 -*- from books import db from books.models.base import Base association_table = db.Table('association', db.Column('book_id', db.Integer, db.ForeignKey('book.id'), primary_key=True), db.Column('author_id', db.Integer, db.ForeignKey('author.id'), primary_key=True) ) class Author(Base): __tablename__ = 'author' name = db.Column(db.String, nullable=False) books = db.relationship("Book", secondary=association_table, backref="book") def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def __repr__(self): return '<name %r>' % self.name
class User(db.Model): id = db.Column(db.Integer, primary_key=True) first_name = db.Column(db.String(128)) last_name = db.Column(db.String(128)) username = db.Column(db.String(128)) password = HASH