Пример #1
0
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: '******')"
Пример #2
0
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.String(100))
    genre = db.Column(db.String(100))
    rating = db.Column(db.Float)
    numRatings = db.Column(db.BigInteger)
    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)
    carts = db.relationship('CartItem', backref=db.backref('book'), lazy=True)

    def __repr__(self):
        return f"Book( titel: '{self.title}' )"
Пример #3
0
class Order(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    order_date = db.Column(db.Date)
    books = db.relationship('Book', secondary=transactions)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))

    def __repr__(self):
        return f"Order( orderID: {self.id}, userID: {self.user_id}, date: {self.order_date})"
Пример #4
0
class Cart(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    date = db.Column(db.Date)
    cart_items = db.relationship('CartItem', backref=db.backref('cart'), lazy=True)

    def __repr__(self):
        return f"ShoppingCart( cart_id: '{self.id}', user_id: '{self.user_id}')"
Пример #5
0
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}' )"
Пример #6
0
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}' )"