Ejemplo n.º 1
0
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
        }
Ejemplo n.º 2
0
class Wishlist(db.Model):
    __tablename__ = 'wishlist'
    wishlist_id = db.Column('wishlist_id',
                            db.Integer,
                            primary_key=True,
                            autoincrement=True)
    cart_fkid = db.Column('cart_fkid', db.Integer,
                          db.ForeignKey('cart.cart_id'))

    def to_representation(self):
        return {'cart_id': self.cart_id}
Ejemplo n.º 3
0
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')
Ejemplo n.º 4
0
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
        }
Ejemplo n.º 5
0
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
        }
Ejemplo n.º 6
0
class Myorder(db.Model):
    __tablename__ = 'myorder'
    myorder_id = db.Column('myorder_id',
                           db.Integer,
                           primary_key=True,
                           autoincrement=True)
    cart_fkid = db.Column('cart_fkid', db.Integer,
                          db.ForeignKey('cart.cart_id'))
    final_amt_to_pay = db.Column('final_amt_to_pay',
                                 db.Integer,
                                 nullable=False)

    def to_representation(self):
        return {
            'myorder_id': self.myorder_id,
            'cart_id': self.cart_id,
            'final_amt_to_pay': self.final_amt_to_pay
        }
Ejemplo n.º 7
0
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
        }
Ejemplo n.º 8
0
from myportalapp import db

associate_table1 = db.Table(
    'associate_table_category',
    db.Column('catg_id',
              db.Integer,
              db.ForeignKey('category.cat_id'),
              primary_key=True),
    db.Column('subcat_id',
              db.Integer,
              db.ForeignKey('subcategory.sub_id'),
              primary_key=True))

associate_table2 = db.Table(
    'associate_table_sub',
    db.Column('subcat_id',
              db.Integer,
              db.ForeignKey('subcategory.sub_id'),
              primary_key=True),
    db.Column('product_id',
              db.Integer,
              db.ForeignKey('product.product_id'),
              primary_key=True))


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,