class GoodsCategory(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(30), unique=True) order_id = db.Column(db.Integer) parent_id = db.Column(db.Integer, db.ForeignKey('goods_category.id'), default=None) goods = db.relationship('Goods', back_populates='category') parent = db.relationship('GoodsCategory', back_populates="sub_cates", remote_side=[id]) sub_cates = db.relationship('GoodsCategory', back_populates="parent", cascade='all, delete-orphan', order_by=order_id) # 重写删除方法,会删除分类其下商品 def delete(self): default_category = GoodsCategory.query.get(1) goods_list = self.goods[:] for goods in goods_list: goods.category = default_category db.session.delete(self) db.session.commit()
class Cart(db.Model): id = db.Column(db.Integer, primary_key=True) goods_id = db.Column(db.Integer, db.ForeignKey('goods.goods_id')) amount = db.Column(db.Integer, default=0) user_id = db.Column(db.Integer, db.ForeignKey('member.user_id')) user = db.relationship('Member') goods = db.relationship('Goods')
class Area(db.Model): place_id = db.Column(db.Integer, primary_key=True) place_name = db.Column(db.String(50)) place_order = db.Column(db.Integer, default=0) parent_id = db.Column(db.Integer, db.ForeignKey('area.place_id'), default=None) up_place = db.relationship('Area', back_populates="sub_place", remote_side=[place_id]) sub_place = db.relationship('Area', back_populates="up_place", cascade='all, delete-orphan', order_by=place_order)
class OrderGoods(db.Model): id = db.Column(db.Integer, primary_key=True) goods_id = db.Column(db.Integer, db.ForeignKey('goods.goods_id')) order_id = db.Column(db.Integer, db.ForeignKey('order.id')) price = db.Column(db.DECIMAL(12, 2)) order_price = db.Column(db.DECIMAL(12, 2)) order_active = db.Column(db.String(255), default=None) amount = db.Column(db.Integer) discount = db.Column(db.DECIMAL(12, 2)) order = db.relationship('Order', back_populates='goods') goods = db.relationship('Goods')
class Region(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(30), unique=True) order_id = db.Column(db.Integer) parent_id = db.Column(db.Integer, db.ForeignKey('region.id'), default=None) parent = db.relationship('Region', back_populates="sub_regs", remote_side=[id]) sub_regs = db.relationship('Region', back_populates="parent", cascade='all, delete-orphan', order_by=order_id) def delete(self): default_region = Region.query.get(1) db.session.delete(self) db.session.commit()
class Order(db.Model): id = db.Column(db.Integer, primary_key=True) order_no = db.Column(db.String(50)) subject = db.Column(db.String(100)) total_price = db.Column(db.DECIMAL(12, 2)) status = db.Column(db.String(10)) seller = db.Column(db.String(50)) buyer = db.Column(db.String(50)) createTime = db.Column(db.DATETIME) payment = db.Column(db.String(20)) paytime = db.Column(db.DATETIME) goods = db.relationship('OrderGoods', back_populates='order', cascade='all, delete-orphan') logistics = db.relationship('Logistics', back_populates='order', cascade='all, delete-orphan')
class Logistics(db.Model): id = db.Column(db.Integer, primary_key=True) order_id = db.Column(db.Integer, db.ForeignKey('order.id')) receiver = db.Column(db.String(20)) mobile = db.Column(db.String(30)) address = db.Column(db.String(100)) status = db.Column(db.String(100)) order = db.relationship('Order')
class OrderGoods(db.Model): id = db.Column(db.Integer, primary_key=True) goods_id = db.Column(db.Integer) order_id = db.Column(db.Integer, db.ForeignKey('order.id')) price = db.Column(db.FLOAT) order_price = db.Column(db.FLOAT) order_active = db.Column(db.Integer, default=None) amount = db.Column(db.Integer) discount = db.Column(db.FLOAT) order = db.relationship('Order', back_populates='goods')
class Goods(db.Model): goods_id = db.Column(db.Integer, primary_key=True) goods_title = db.Column(db.String(100)) goods_subhead = db.Column(db.String(100)) category_id = db.Column(db.Integer, db.ForeignKey('goods_category.id')) thumb = db.Column(db.String(100)) main_pic = db.Column(db.String(500)) price = db.Column(db.DECIMAL(12, 2)) detail = db.Column(db.TEXT) create_time = db.Column(db.DateTime) is_recommend = db.Column(db.Integer) category = db.relationship('GoodsCategory')
class Goods(db.Model): ''' 商品模型 goods_id : 商品主键 goods_title : 商品标题 goods_subhead : 商品副标题 category_id : 商品分类 main_pic : 商品主图 price : 商品价格 detail : 商品详情 ''' goods_id = db.Column(db.Integer, primary_key=True) goods_title = db.Column(db.String(100)) goods_subhead = db.Column(db.String(100)) category_id = db.Column(db.Integer, db.ForeignKey('goods_category.id')) thumb = db.Column(db.String(100)) main_pic = db.Column(db.String(500)) price = db.Column(db.DECIMAL) detail = db.Column(db.TEXT) create_time = db.Column(db.DateTime) category = db.relationship('GoodsCategory')