Example #1
0
class Base(db.Model):
    __abstract__ = True

    id = db.Column(UUID, primary_key=True, default=uuid.uuid4)
    created_at = db.Column(
        db.DateTime, nullable=False, default=datetime.utcnow, index=True)
    modified_at = db.Column(
        db.DateTime,
        nullable=False,
        default=datetime.utcnow,
        onupdate=datetime.utcnow)

    def serialize(self):
        rv = {}
        attributes = getattr(self, 'serializable')
        for attribute in attributes:
            if isinstance(getattr(self, attribute), datetime) or \
                    isinstance(getattr(self, attribute), date):
                datetime_attr_value = getattr(self, attribute)
                rv[attribute] = datetime_attr_value\
                    .isoformat().replace('T', ' ')
            elif isinstance(getattr(self, attribute), Enum):
                rv[attribute] = getattr(self, attribute).name
            else:
                rv[attribute] = getattr(self, attribute)

        return rv
Example #2
0
class Item(Base):
    __tablename__ = 'items'
    product_id = db.Column(
        UUID, db.ForeignKey('products.id'), nullable=False)
    product = db.relationship(
        'Product', backref=db.backref('items'))

    cart_id = db.Column(
        UUID, db.ForeignKey('carts.id'), nullable=False)
    cart = db.relationship(
        'Cart', backref=db.backref('items'))

    quantity = db.Column(db.Integer)
    price  = db.Column(db.Float(precision=2), nullable=False)




    serializable = [
        'id', 'product_id', 'cart_id', 'quantity',
        'price', 'created_at', 'modified_at'
    ]

    def serialize(self):
        rv = super(Member, self).serialize()
        return rv
Example #3
0
class Subscription(Base):
    __tablename__ = 'subscriptions'
    start_date = db.Column(db.Date, nullable=False)
    end_date = db.Column(db.Date, nullable=False)


    serializable = ['id', 'start_date', 'end_date']

    def serialize(self):
        rv = super(Subscription, self).serialize()
        return rv
Example #4
0
class Cart(Base):
    __tablename__ = 'carts'
    account_id = db.Column(UUID, db.ForeignKey('accounts.id'), nullable=False)
    account = db.relationship('Account', backref=db.backref('carts'))
    active = db.Column(db.Boolean, default=True)

    serializable = ['id']

    def serialize(self):
        rv = super(Subscription, self).serialize()
        return rv
Example #5
0
class ProductSubcategory(Base):
    __tablename__ = 'product_subcategories'
    product_category_id = db.Column(UUID,
                                    db.ForeignKey('product_categories.id'),
                                    nullable=False)
    product_category = db.relationship(
        'ProductCategory', backref=db.backref('product_subcategories'))

    name = db.Column(db.String(80), nullable=False)
    description = db.Column(db.String(80), nullable=True)

    serializable = ['id', 'product_category_id', 'name', 'description']

    def serialize(self):
        rv = super(Subscription, self).serialize()
        return rv
Example #6
0
class Product(Base):
    __tablename__ = 'products'
    product_subcategory_id = db.Column(
        UUID, db.ForeignKey('product_subcategories.id'), nullable=False)
    product_subcategory = db.relationship('ProductSubcategory',
                                          backref=db.backref('products'))

    name = db.Column(db.String(20), nullable=False)
    description = db.Column(db.Text(), nullable=True)
    price = db.Column(db.Float(precision=2), nullable=False)
    available_item_count = db.Column(db.Integer)
    image = db.Column(db.String(20), nullable=False)

    serializable = [
        'id', 'product_subcategory_id', 'name', 'description', 'price',
        'available_item_count', 'created_at', 'modified_at'
    ]

    def serialize(self):
        rv = super(Member, self).serialize()
        return rv
Example #7
0
class Member(Base):
    __tablename__ = 'subscription_members'
    subscription_id = db.Column(UUID,
                                db.ForeignKey('subscriptions.id'),
                                nullable=False)
    subscription = db.relationship('Subscription',
                                   backref=db.backref('members'))
    name = db.Column(db.String(80), nullable=False)
    mobile = db.Column(db.String(20), index=True)
    email = db.Column(db.String(50))
    age = db.Column(db.Integer)
    gender = db.Column(db.Enum(Gender))

    serializable = [
        'id', 'subscription_id', 'name', 'mobile', 'email', 'age', 'gender',
        'created_at', 'modified_at'
    ]

    def serialize(self):
        rv = super(Member, self).serialize()
        return rv