class OAuth(db.Model): id = db.Column(db.Integer, primary_key=True) authorized_from = db.Column(db.String(30)) authorized = db.Column(db.String(30)) authorized_info = db.Column(db.String(500)) bind_to_username = db.Column(db.String(30)) bind_date = db.Column(db.DateTime)
class Address(db.Model): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('member.user_id'), default=None) receiver = db.Column(db.String(20)) mobile = db.Column(db.String(30)) address = db.Column(db.String(100))
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 Admin(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20)) password_hash = db.Column(db.String(128)) def set_password(self, password): self.password_hash = generate_password_hash(password) def validate_password(self, password): return check_password_hash(self.password_hash, password)
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 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 Member(db.Model, UserMixin): user_id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(30)) password_hash = db.Column(db.String(128)) email = db.Column(db.String(50)) reg_date = db.Column(db.DateTime) reg_ip = db.Column(db.String(50)) reg_sex = db.Column(db.String(2)) last_login_ip = db.Column(db.String(50)) last_login_time = db.Column(db.DateTime) mobile = db.Column(db.String(20)) is_approve = db.Column(db.Boolean) is_admin = db.Column(db.Boolean) # 加密用户密码 def set_password(self, password): self.password_hash = generate_password_hash(password) # 验证用户密码 def validate_password(self, password): return check_password_hash(self.password_hash, password) # 重写方法,获取用户ID def get_id(self): return str(self.user_id)
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 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')
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')