コード例 #1
0
class Product(Base):
    __tablename__ = 'products'

    name  = db.Column(db.String(50), unique=True, nullable=False)
    slug =  db.Column(db.String(50), unique=True, nullable=False)
    description  = db.Column(db.Text())
    meta_description  = db.Column(db.String(500))
    meta_keywords  = db.Column(db.String(500))
    sku = db.Column(db.String(100))
    model = db.Column(db.String(200))
    price = db.Column(db.Float())
    old_price = db.Column(db.Float())
    image_url = db.Column(db.String(250))
    is_bestseller = db.Column(db.Boolean())     
    is_featured = db.Column(db.Boolean())    
    quantity = db.Column(db.Integer())
    categories = db.relationship('Category',secondary=product_category,lazy='subquery')
    brands = db.relationship('Brand',secondary=product_brand,lazy='subquery')
    product_status  = db.Column('product_status', Enum(StatusType))
    
    def sale_price(self):           
        if self.old_price > self.price:                
            return self.price           
        else:                
            return None

    def __repr__(self):
        return self.name
コード例 #2
0
class Base(db.Model):
    __abstract__ = True
    id = db.Column(db.Integer, primary_key=True)
    created_date = db.Column(db.DateTime(), default=datetime.now())
    modified_date = db.Column(db.DateTime(),
                              default=datetime.now(),
                              onupdate=datetime.now())
    is_deleted = db.Column(db.Boolean(), default=False)