class Author(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100),unique=True) info = db.Column(db.Text) img = db.Column(db.String(100)) books = db.relationship('Book', secondary=author_book_relationship, backref=db.backref('authors')) def __repr__(self): return f"Author( name: '{self.name}' )"
class CreditCard(db.Model): id = db.Column(db.Integer, primary_key=True) card_type = db.Column(db.String(20)) # I actually don't know if this cvv attribute shoult be a string or an Integer card_number = db.Column(db.String(20), unique=True) cvv = db.Column(db.Integer) exp_date = db.Column(db.Date) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) def __repr__(self): return f"CreditCard( card_number: '{self.card_number[:4]}', user: '******')"
class User(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(30), nullable=False) 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) address = db.Column(db.String, nullable=False) orders = db.relationship('Order', backref='user', lazy=True) comments = db.relationship('Comment', backref=db.backref('user'), lazy=True) def __repr__(self): return f"User( email: '{self.email}', username: '******')"
class Book(db.Model): isbn = db.Column(db.BigInteger, primary_key=True) title = db.Column(db.String(100), unique=True, nullable=False) date_pub = db.Column(db.Date) genre = db.Column(db.String(100)) rating = db.Column(db.Integer) price = db.Column(db.Float) img = db.Column(db.String(100)) pub_info = db.Column(db.Text) book_description = db.Column(db.Text) comments = db.relationship('Comment', backref=db.backref('book'), lazy=True) def __repr__(self): return f"Book( titel: '{self.title}' )"
class Author(db.Model): name = db.Column(db.String(100), primary_key=True) info = db.Column(db.Text, nullable=False) books = db.relationship('Book', secondary=publish, backref=db.backref('authors')) def __repr__(self): return f"Author( name: '{self.name}' )"
from geektext import db #relationship table between Author and Book. since it is a many to many relaitonship we need a new table called publish publish = db.Table( 'publish', db.Column('book_isbn', db.BigInteger, db.ForeignKey('book.isbn'), primary_key=True), db.Column('author_name', db.String(100), db.ForeignKey('author.name'), primary_key=True)) class Author(db.Model): name = db.Column(db.String(100), primary_key=True) info = db.Column(db.Text, nullable=False) books = db.relationship('Book', secondary=publish, backref=db.backref('authors')) def __repr__(self): return f"Author( name: '{self.name}' )" transactions = db.Table( 'transactions', db.Column('book_isbn', db.BigInteger,
from enum import unique from geektext import db, login_manager from flask_login import UserMixin @login_manager.user_loader def load_user(user_id): return User.query.get(int(user_id)) #author_book_relationship is a table with two columns book_isbn and author_name #it relates a book with the author that wrote it author_book_relationship = db.Table('author_book_relationship', db.Column('book_isbn', db.BigInteger, db.ForeignKey('book.isbn'), primary_key=True), db.Column('author_name', db.String(100), db.ForeignKey('author.name'), primary_key=True) ) #Author is a table that contains every author in the database #The attributes are: name, info, and books class Author(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100),unique=True) info = db.Column(db.Text) img = db.Column(db.String(100)) books = db.relationship('Book', secondary=author_book_relationship, backref=db.backref('authors')) def __repr__(self): return f"Author( name: '{self.name}' )" #order_book_relationship is a table that relates an order with the books that is contains