コード例 #1
0
class Shipment(db.Model, CRUDMixin, BaseModel):
    __tablename__ = 'shipment'
    order_id = db.Column('order_id', db.ForeignKey('order.id'))
    shipment_status = db.Column('shipment_status', db.Enum(ShipmentStatus))

    def __init__(self, **kwargs):
        db.Model.__init__(self,
                          shipment_number=kwargs.get('shipment_number'),
                          shipment_status=kwargs.get('shipment_status'),
                          )
コード例 #2
0
ファイル: models.py プロジェクト: GhostFanta/shop.flask.zc
class ProductReview(db.Model, CRUDMixin, BaseModel):
    __tablename__ = 'productreview'
    rating = db.Column('rating', db.Integer)
    review = db.Column('review', db.Text)
    product_id = db.Column('product_id', db.ForeignKey('product.id'))

    product = relationship('Product', backref=db.backref('productreview'))

    def __init__(self, **kwargs):
        db.Model.__init__(self,
                          rating=kwargs.get('rating'),
                          review=kwargs.get('review'),
                          product_id=kwargs.get('product_id'))
コード例 #3
0
ファイル: models.py プロジェクト: GhostFanta/shop.flask.zc
class Order(db.Model, BaseModel, CRUDMixin):
    """
    It represents the proceed cart.
    """

    __tablename__ = 'order'
    status = db.Column('status', db.Enum(OrderStatus), default=OrderStatus.unshipped)
    processed_at = db.Column('processed_at', db.DateTime)

    def __init__(self, **kwargs):
        db.Model.__init__(self,
                          status=kwargs.get('status')
                          )
コード例 #4
0
class ShipmentTrack(db.Model, CRUDMixin, BaseModel):
    __tablename__ = 'shipmenttrack'
    shipment_date = db.Column('shipment_date', db.Enum(ShipmentStatus))
    esitmated_arrival = db.Column('estimated_arrival', db.DateTime)
    track_number = db.Column('track_number', db.String(200))
    shipment_id = db.Column('shipment_id', db.ForeignKey('shipment.id'))

    shipment = relationship("Shipment", backref="shipmenttrack")

    def __init__(self, **kwargs):
        db.Model.__init__(self,
                          shipment_date=kwargs.get('shipment_date'),
                          estimated_arrival=kwargs.get('esitmated_arrival'),
                          track_number=kwargs.get('track_number')
                          )
コード例 #5
0
ファイル: models.py プロジェクト: GhostFanta/shop.flask.zc
class Cart(db.Model, CRUDMixin):
    """
    Contains a list of items, which indicates the items that the customer want to
    proceed.
    """
    __tablename__ = 'cart'
    id = db.Column('id', db.Integer, autoincrement=True, nullable=False, unique=True, primary_key=True)
    user_id = db.Column('user_id', db.ForeignKey('user.id'))

    items = db.relationship('Item', backref=db.backref("cart_items"))
    user = db.relationship("User", backref=db.backref("user_cart"))

    def __init__(self, **kwargs):
        db.Model.__init__(self,
                          user_id=kwargs.get('user_id')
                          )
コード例 #6
0
class User(db.Model, CRUDMixin, BaseModel):
    __tablename__ = 'user'
    name = db.Column('name', db.String(200))
    salt = db.Column('salt', db.String(200))
    password = db.Column('password', db.String(200))
    email = db.Column('email', db.String(200))
    avatar = db.Column('avatar', db.String(256))
    last_login = db.Column('last_login', db.DateTime, default=datetime.utcnow)
    status = db.Column('status', db.Enum(AccountStatus))

    cart = db.relationship("Cart", backref=db.backref("cart_user"))
    address = db.relationship("Address", backref=db.backref("user_address"))

    def __init__(self, **kwargs):
        db.Model.__init__(self,
                          name=kwargs.get('name'),
                          salt=kwargs.get('salt'),
                          password=kwargs.get('password'),
                          email=kwargs.get('email'),
                          status=kwargs.get('status') or AccountStatus.inactive,
                          last_login=kwargs.get('last_login') or datetime.utcnow(),
                          )

    def __str__(self):
        return
コード例 #7
0
ファイル: models.py プロジェクト: GhostFanta/shop.flask.zc
class Category(db.Model, CRUDMixin, BaseModel):
    __tablename__ = 'category'
    category_name = db.Column('category_name', db.String(20))

    product = db.relationship("Product", backref="category_product")

    def __init__(self, **kwargs):
        db.Model.__init__(self, category_name=kwargs.get('category_name'))

    def __repr__(self):
        return '<Category %r>' % self.__category_name
コード例 #8
0
class Address(db.Model, CRUDMixin, BaseModel):
    __tablename__ = 'address'
    street = db.Column('street', db.String(200))
    city = db.Column('city', db.String(128))
    state = db.Column('state', db.String(200))
    zip_code = db.Column('zip_code', db.String(10))
    user_id = db.Column('user_id', db.ForeignKey('user.id'))

    user = relationship('User', backref=db.backref('user_address'))

    def __init__(self, **kwargs):
        db.Model.__init__(self,
                          street=kwargs.get('street'),
                          city=kwargs.get('city'),
                          state=kwargs.get('state'),
                          zip_code=kwargs.get('zip_code'),
                          user_id=kwargs.get('user_id') or None
                          )

    def __str__(self):
        return "ID=%d, City=%s, State=%d" % (self.id, self.city, self.state)
コード例 #9
0
ファイル: models.py プロジェクト: GhostFanta/shop.flask.zc
class Product(db.Model, CRUDMixin, BaseModel):
    __tablename__ = 'product'
    product_name = db.Column('product_name', db.String(200))
    description = db.Column('description', db.String(200))
    price = db.Column('price', db.DECIMAL)
    produced_at = db.Column('produced_at', db.DateTime)
    capacity = db.Column('capacity', db.Integer)
    category_id = db.Column('category', db.ForeignKey('category.id'))

    item = relationship('Item', backref="item_product")
    category = relationship('Category', backref=db.backref("product_category"))
    reviews = relationship('ProductReview',
                           backref=db.backref("product_review"))

    def __init__(self, **kwargs):
        db.Model.__init__(
            self,
            product_name=kwargs.get('product_name'),
            description=kwargs.get('description'),
            price=kwargs.get('price'),
            capacity=kwargs.get('capacity'),
            category=kwargs.get('category'),
        )

    @classmethod
    def add_amount(cls, product_id, amount):
        product = cls.get(product_id)
        product.capacity = product.capacity + amount
        product.save()

    @classmethod
    def reduce_amount(cls, product_id, amount):
        product = cls.get(product_id)
        product.capacity = product.capacity - amount
        product.save()
コード例 #10
0
ファイル: models.py プロジェクト: DMS/shop.flask.zc
class Item(db.Model, BaseModel, CRUDMixin):
    """
    One row in cart, which contains the info of a product and the number of
    products that the customer want to purchase.
    """
    __tablename__ = 'item'
    product_id = db.Column(db.Integer, db.ForeignKey('product.id'))
    cart_id = db.Column(db.Integer, db.ForeignKey('cart.id'))
    amount = db.Column('amount', db.Integer, default=0)

    cart = relationship("Cart", backref="item_cart")
    product = relationship("Product", backref="item_product")

    def __init__(self, **kwargs):
        db.Model.__init__(self,
                          product_id=kwargs.get('product_id'),
                          amount=kwargs.get('amount'),
                          cart_id=kwargs.get('cart_id'))

    @property
    def price(self):
        return self.product.price * self.amount
コード例 #11
0
ファイル: models.py プロジェクト: GhostFanta/shop.flask.zc
class Tag(db.Model, BaseModel):
    __tablename__ = 'tag'
    tag_name = db.Column('tag_name', db.String(20))

    def __init__(self, **kwargs):
        db.Model.__init__(self, name=kwargs.get('tag_name'))