class Cart(db.Model): __tablename__ = 'cart' cart_id = db.Column('cart_id', db.Integer, primary_key=True, autoincrement=True) customer_idf = db.Column('customer_idf', db.Integer, db.ForeignKey('user_table.cust_id')) product_idf = db.Column('product_idf', db.Integer, db.ForeignKey('product.product_id')) quantity_to_buy = db.Column('quantity_to_buy', db.Integer, nullable=False) wishlistkey = db.relationship('Wishlist', backref='cart', lazy=True, uselist=False, cascade='all,delete') myorderkey = db.relationship('Myorder', backref='cart', lazy=True, uselist=False, cascade='all,delete') def to_representation(self): return { 'customer_id': self.cutomer_id, 'product_id': self.product_id, 'quantity_to_buy': self.quantity_to_buy }
class User_table(db.Model): cust_id = db.Column('cust_id', db.Integer, primary_key=True, autoincrement=True) cust_name = db.Column('cust_name', db.String(64)) cust_pwd = db.Column('cust_pwd', db.String(64)) cust_address = db.Column('cust_address', db.String(100)) cust_fk = db.relationship('Cart', backref='user_table', lazy=True, uselist=False, cascade='all,delete')
class Subcategory(db.Model): __tablename__ = 'subcategory' sub_id = db.Column('sub_id', db.Integer, primary_key=True) sub_name = db.Column('sub_name', db.String(64)) productfk = db.relationship('Product', secondary=associate_table2, backref='subcategory', lazy='joined', cascade='all,delete') def to_representation(self): productfk = [x.to_representation() for x in self.productfk] return { 'sub_id': self.sub_id, 'sub_name': self.sub_name, 'product': productfk }
class Category(db.Model): __tablename__ = 'category' cat_id = db.Column('cat_id', db.Integer, primary_key=True) cat_name = db.Column('cat_name', db.String(64)) subfk = db.relationship('Subcategory', secondary=associate_table1, backref='category', lazy='joined', cascade='all,delete') def to_representation(self): subfk = [x.to_representation() for x in self.subfk] return { 'cat_id': self.cat_id, 'cat_name': self.cat_name, 'subcategory': subfk }
class Product(db.Model): __tablename__ = 'product' product_id = db.Column('product_id', db.Integer, primary_key=True, autoincrement=True) product_name = db.Column('product_name', db.String(64)) cost = db.Column('cost', db.Integer) avail_stock = db.Column('avail_stock', db.Integer) productkey = db.relationship('Cart', backref='product', lazy=True, uselist=False, cascade='all,delete') def to_representation(self): return { 'product_id': self.product_id, 'product_name': self.product_name, 'cost': self.cost, 'avail_stock': self.avail_stock }