Exemplo n.º 1
0
class Variantoptions(Base):
    __category__ = 'Product'

    available_for_sale = db.Column(db.Boolean, default=False)
    currently_not_in_stock = db.Column(db.Boolean)
    requires_shipping = db.Column(db.Boolean)
    quantity_available = db.Column(db.Integer)
    compare_at_price = db.Column(db.Float)
    unit_price = db.Column(db.Float)
    weight = db.Column(db.Float)
    price = db.Column(db.Float)
    namespace = db.Column(db.String)
    title = db.Column(db.String)
    sku = db.Column(db.String)
    key = db.Column(db.String)
    selected_options = db.relationship('Option',
                                       secondary=variants_options_relation,
                                       backref=db.backref('variantoptions',
                                                          lazy='dynamic'))
    images = db.relationship('Image',
                             secondary=images_options_relation,
                             backref=db.backref('variantoptions',
                                                lazy='dynamic'))
    metafield = db.relationship('Metafield',
                                backref='variant_options',
                                lazy=True,
                                uselist=True)
    product = db.Column(db.Integer, db.ForeignKey('product.id'))
Exemplo n.º 2
0
class StoreModel(db.Model):
    __tablename__ = 'stores'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80))

    items = db.relationship('ItemModel', lazy='dynamic')

    def __init__(self, name):
        self.name = name

    def json(self):
        return {
            'id': self.id,
            'name': self.name,
            'items': [item.json() for item in self.items.all()]
        }

    @classmethod
    def find_by_name(cls, name):
        return cls.query.filter_by(name=name).first()

    @classmethod
    def find_all(cls):
        return cls.query.all()

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()

    def delete_from_db(self):
        db.session.delete(self)
        db.session.commit()
Exemplo n.º 3
0
class Domain(Base):
    __category__ = 'Shop'

    host = db.Column(db.String)
    ssl_enabled = db.Column(db.Boolean)
    url = db.Column(db.String)
    shops = db.relationship('Shop',
                            lazy=True,
                            uselist=True,
                            backref=db.backref('domain', uselist=True))
Exemplo n.º 4
0
class ItemModel(db.Model):
    __tablename__ = 'items'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80))
    price = db.Column(db.Float(precision=2))

    store_id = db.Column(db.Integer, db.ForeignKey('stores.id'))
    store = db.relationship('StoreModel')

    def __init__(self, name, price, store_id):
        self.name = name
        self.price = price
        self.store_id = store_id

    def json(self):
        return {
            'id': self.id,
            'name': self.name,
            'price': self.price,
            'store_id': self.store_id
        }

    @classmethod
    def find_by_name(cls, name):
        return cls.query.filter_by(name=name).first()

    @classmethod
    def find_all(cls):
        return cls.query.all()

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()

    def delete_from_db(self):
        db.session.delete(self)
        db.session.commit()
Exemplo n.º 5
0
class Product(Base, DateTimeMixin):
    __category__ = 'Product'

    sku = db.Column(db.String(255), nullable=False)
    title = db.Column(db.String)
    key = db.Column(db.String(30))  # required
    product_type = db.Column(db.String)
    description = db.Column(db.String)
    handle = db.Column(
        db.String
    )  # auto generate from title . like Black Shirt --> Black-Shirt
    descriptionHtml = db.Column(db.String)
    vendor = db.Column(db.String)
    namespace = db.Column(db.String(20), nullable=False)
    taxable = db.Column(db.Boolean(), default=False)
    available_for_sale = db.Column(db.Boolean(), default=False)
    total_inventory = db.Column(db.Integer, nullable=False)
    created_at = db.Column(db.DateTime(), default=db.func.now())
    updated_at = db.Column(db.DateTime(),
                           onupdate=db.func.now(),
                           default=db.func.now())
    metafields = db.relationship('Metafield', backref='prod', uselist=True)
    price_range = db.relationship('Pricerange',
                                  backref='pricerange',
                                  uselist=True)
    options = db.relationship('Option',
                              secondary=options_products_relation,
                              backref=db.backref('products', lazy='dynamic'))
    tags = db.relationship('Tag',
                           secondary=tags_products_relation,
                           backref=db.backref('products', lazy='dynamic'))
    selected_options = db.relationship(
        'Selectedinput',
        secondary=selected_options_products_relation,
        backref=db.backref('products', lazy='dynamic'))
    variant_by_selected_options = db.relationship(
        'Variantoptions',
        lazy=True,
        uselist=True,
        backref=db.backref('products', uselist=True))

    @classmethod
    def get_by_sku(cls, sku):
        return cls.query.filter_by(sku=sku).first()
Exemplo n.º 6
0
class Service(Policy):
    shop = db.relationship('Shop',
                           lazy=True,
                           uselist=True,
                           backref=db.backref('terms_of_service',
                                              uselist=False))
Exemplo n.º 7
0
class Refund(Policy):
    shop = db.relationship('Shop',
                           lazy=True,
                           uselist=True,
                           backref=db.backref('refund_policy', uselist=False))
Exemplo n.º 8
0
class Privacy(Policy):
    shop = db.relationship('Shop',
                           lazy=True,
                           uselist=True,
                           backref=db.backref('privacy_policy', uselist=False))
Exemplo n.º 9
0
class Valuetype(Base):
    __category__ = 'Product'

    value = db.Column(db.String)
    metafields = db.relationship('Metafield', backref='valuetype', lazy=True)