class Product(db.Model): __tablename__ = 'product' id = db.Column(db.String(50), primary_key=True) pname = db.Column(db.String(255), nullable=False) old_price = db.Column(db.Float, nullable=False) new_price = db.Column(db.Float, nullable=False) images = db.Column(db.Text) pDesc = db.Column(db.Text) head_img = db.Column(db.Text) is_hot = db.Column(db.Integer, default=0) # 0不是热卖品,1热卖品 2推广品 is_sell = db.Column(db.Integer, default=1) # 0销完 1在售 is_pass = db.Column(db.Integer, default=0) # 0正在审核 1审核未通过 2 审核通过 pdate = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now) click_count = db.Column(db.Integer, default=0) counts = db.Column(db.Integer, nullable=False) love_user = db.Column(db.Text) # 喜爱的人 uid = db.Column(db.String(50), db.ForeignKey("user.id", ondelete='cascade')) user = db.relationship("User", backref=db.backref('products', order_by=pdate.desc())) csid = db.Column(db.String(50), db.ForeignKey("category_second.id", ondelete='cascade')) categorysecond = db.relationship("CategorySecond", backref=db.backref("products", order_by=pdate.desc())) def product_json(self): product_json = {} # product_json["pdate"] = self.pdate product_json["id"] = self.id product_json["pname"] = self.pname product_json["images"] = self.images.split('@')[0] product_json["counts"] = self.counts product_json["old_price"] = self.old_price product_json["new_price"] = self.new_price return product_json def product_json2(self): product_json = {} product_json["pdate"] = self.pdate product_json["id"] = self.id product_json["pname"] = self.pname return product_json def product_json1(self): product_json = {} product_json["id"] = self.id product_json["pname"] = self.pname product_json["images"] = self.images product_json["counts"] = self.counts product_json["old_price"] = self.old_price product_json["new_price"] = self.new_price product_json["pDesc"] = self.pDesc product_json["new_price"] = self.new_price return product_json
class OrderItem(db.Model): __tablename__ = "order_item" id = db.Column(db.String(50), primary_key=True) count = db.Column(db.Integer, nullable=False) sub_total = db.Column(db.Float, nullable=False) pid = db.Column(db.String(50), db.ForeignKey("product.id", ondelete='cascade')) product = db.relationship("Product", backref=db.backref("orderItems")) oid = db.Column(db.String(50), db.ForeignKey("order.id", ondelete='cascade')) order = db.relationship("Order", backref=db.backref("orderItems"))
class ShopCart(db.Model): __tablename__ = "shop_cart" id = db.Column(db.String(50), primary_key=True) sdate = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now) count = db.Column(db.Integer) subTotal = db.Column(db.Float) uid = db.Column(db.String(50), db.ForeignKey("user.id", ondelete='cascade')) user = db.relationship("User", backref=db.backref("shopcarts", order_by=sdate.desc())) pid = db.Column(db.String(50), db.ForeignKey("product.id")) product = db.relationship('Product', backref=db.backref("shopcarts"))
class Comment(db.Model): __tablename__ = 'comment' id = db.Column(db.String(50), primary_key=True) content = db.Column(db.Text, nullable=False) is_read = db.Column(db.Integer, default=0) # 是否看过 0看过,1没有看过 cdate = db.Column(db.DateTime, default=datetime.now) uid = db.Column(db.String(50), db.ForeignKey("user.id", ondelete='cascade')) user = db.relationship("User", backref=db.backref('commments', order_by=cdate.desc())) comment_id = db.Column(db.String(50), db.ForeignKey('comment.id')) comment_parent = db.relationship("Comment", backref=db.backref("comments"), remote_side=[id]) pid = db.Column(db.String(50), db.ForeignKey('product.id')) product = db.relationship("Product", backref=db.backref('commments', order_by=cdate.desc()))
class Chapter(db.Model): __tablename__ = 'chapter' id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(50), nullable=False) need_vip = db.Column(db.BOOLEAN, default=False) book_id = db.Column(db.Integer, db.ForeignKey('book.id')) book = db.relationship('Book', backref=db.backref('chapters')) category = db.relationship('Category', secondary=category_chapter, backref=db.backref('chapters'))
class Category(db.Model): __tablename__ = 'category' id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(50), nullable=False) fatherc_id = db.Column(db.Integer, db.ForeignKey('fatherc.id')) fatherc = db.relationship('Fatherc', backref=db.backref('categorys'))
class CategorySecond(db.Model): __tablename__ = 'category_second' id = db.Column(db.String(50), primary_key=True) csname = db.Column(db.String(255), nullable=False) cid = db.Column(db.String(50), db.ForeignKey('category.id', ondelete='cascade')) category = db.relationship("Category", backref=db.backref('categoryseconds'))
class CategorySecond(db.Model): __tablename__ = 'category_second' id = db.Column(db.String(50), primary_key=True) csname = db.Column(db.String(255), nullable=False) cid = db.Column(db.String(50), db.ForeignKey('category.id', ondelete='cascade')) category = db.relationship("Category", backref=db.backref('categoryseconds')) def categorySecond_json(self): categorySecond_json = {} categorySecond_json["id"] = self.id categorySecond_json["csname"] = self.csname return categorySecond_json
class Order(db.Model): __tablename__ = "order" id = db.Column(db.String(50), primary_key=True) total_money = db.Column(db.Float) ordertime = db.Column(db.DateTime, default=datetime.now) state = db.Column(db.Integer, default=0) # 0未支付,1送达中 2送达完毕 name = db.Column(db.String(50), nullable=False) phone = db.Column(db.String(50), nullable=False) addr = db.Column(db.String(255), nullable=False) uid = db.Column(db.String(50), db.ForeignKey("user.id", ondelete='cascade')) user = db.relationship("User", backref=db.backref("orders", order_by=ordertime.desc())) order_last_time = db.Column(db.String(50))
class Book(db.Model): __tablename__ = 'book' id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(50), nullable=False) need_vip = db.Column(db.BOOLEAN, default=False) introduce = db.Column(db.Text, nullable=True) book_image = db.Column(db.String(50), nullable=True) isdelate = db.Column(db.BOOLEAN, default=False) # 这个外键就不需要了,呀好坑 # category_id = db.Column(db.Integer, db.ForeignKey('category.id')) category = db.relationship('Category', secondary=category_book, backref=db.backref('books'))