class Comment(BaseModel, db.Model): """评论""" __tablename__ = "info_comment" id = db.Column(db.Integer, primary_key=True) # 评论编号 user_id = db.Column(db.Integer, db.ForeignKey("info_user.id"), nullable=False) # 用户id news_id = db.Column(db.Integer, db.ForeignKey("info_news.id"), nullable=False) # 新闻id content = db.Column(db.Text, nullable=False) # 评论内容 parent_id = db.Column(db.Integer, db.ForeignKey("info_comment.id")) # 父评论id parent = db.relationship("Comment", remote_side=[id]) # 自关联 like_count = db.Column(db.Integer, default=0) # 点赞条数 def to_dict(self): resp_dict = { "id": self.id, "create_time": self.create_time.strftime("%Y-%m-%d %H:%M:%S"), "content": self.content, "parent": self.parent.to_dict() if self.parent else None, "user": User.query.get(self.user_id).to_dict(), "news_id": self.news_id, "like_count": self.like_count } return resp_dict
class News(BaseModel, db.Model): """新闻""" __tablename__ = "info_news" id = db.Column(db.Integer, primary_key=True) # 新闻编号 title = db.Column(db.String(256), nullable=False) # 新闻标题 source = db.Column(db.String(64), nullable=False) # 新闻来源 digest = db.Column(db.String(512), nullable=False) # 新闻摘要 content = db.Column(db.Text, nullable=False) # 新闻内容 clicks = db.Column(db.Integer, default=0) # 浏览量 index_image_url = db.Column(db.String(256)) # 新闻列表图片路径 category_id = db.Column(db.Integer, db.ForeignKey("info_category.id")) user_id = db.Column(db.Integer, db.ForeignKey("info_user.id")) # 当前新闻的作者id status = db.Column(db.Integer, default=0) # 当前新闻状态 如果为0代表审核通过,1代表审核中,-1代表审核不通过 reason = db.Column(db.String(256)) # 未通过原因,status = -1 的时候使用 # 当前新闻的所有评论 comments = db.relationship("Comment", lazy="dynamic") def to_review_dict(self): """新闻审核时使用的""" resp_dict = { "id": self.id, "title": self.title, "create_time": self.create_time.strftime("%Y-%m-%d %H:%M:%S"), "status": self.status, "reason": self.reason if self.reason else "" } return resp_dict def to_basic_dict(self): """新闻列表时使用的""" resp_dict = { "id": self.id, "title": self.title, "source": self.source, "digest": self.digest, "create_time": self.create_time.strftime("%Y-%m-%d %H:%M:%S"), "index_image_url": self.index_image_url, "clicks": self.clicks, } return resp_dict def to_dict(self): """新闻详情时使用的""" resp_dict = { "id": self.id, "title": self.title, "source": self.source, "digest": self.digest, "create_time": self.create_time.strftime("%Y-%m-%d %H:%M:%S"), "content": self.content, "comments_count": self.comments.count(), "clicks": self.clicks, "category": self.category.to_dict(), "index_image_url": self.index_image_url, "author": self.user.to_dict() if self.user else None } return resp_dict
class UserFollow(db.Model): __tablename__ = "info_user_fans" follower_id = db.Column(db.Integer, db.ForeignKey("info_user.id"), primary_key=True) # 粉丝id followed_id = db.Column(db.Integer, db.ForeignKey("info_user.id"), primary_key=True) # 作者id
class UserCollection(db.Model, BaseModel): __tablename__ = "info_user_collection" user_id = db.Column(db.Integer, db.ForeignKey("info_user.id"), primary_key=True) # 用户id news_id = db.Column(db.Integer, db.ForeignKey("info_news.id"), primary_key=True) # 新闻id
class Order(BaseModel, db.Model): """订单""" __tablename__ = "ih_order_info" id = db.Column(db.Integer, primary_key=True) # 订单编号 user_id = db.Column(db.Integer, db.ForeignKey("ih_user_profile.id"), nullable=False) # 下订单的用户编号 house_id = db.Column(db.Integer, db.ForeignKey("ih_house_info.id"), nullable=False) # 预订的房间编号 begin_date = db.Column(db.DateTime, nullable=False) # 预订的起始时间 end_date = db.Column(db.DateTime, nullable=False) # 预订的结束时间 days = db.Column(db.Integer, nullable=False) # 预订的总天数 house_price = db.Column(db.Integer, nullable=False) # 房屋的单价 amount = db.Column(db.Integer, nullable=False) # 订单的总金额 status = db.Column( # 订单的状态 db.Enum( "WAIT_ACCEPT", # 待接单, "WAIT_PAYMENT", # 待支付 "PAID", # 已支付 "WAIT_COMMENT", # 待评价 "COMPLETE", # 已完成 "CANCELED", # 已取消 "REJECTED" # 已拒单 ), default="WAIT_ACCEPT", index=True) comment = db.Column(db.Text) # 订单的评论信息或者拒单原因 def to_dict(self): """将订单信息转换为字典数据""" order_dict = { "order_id": self.id, "title": self.house.title, "img_url": constants.QINIU_DOMIN_PREFIX + self.house.index_image_url if self.house.index_image_url else "", "start_date": self.begin_date.strftime("%Y-%m-%d"), "end_date": self.end_date.strftime("%Y-%m-%d"), "ctime": self.create_time.strftime("%Y-%m-%d %H:%M:%S"), "days": self.days, "amount": self.amount, "status": self.status, "comment": self.comment if self.comment else "" } return order_dict
class Collection(BaseModel, db.Model): """用户收藏视频的表""" __tablename__ = "collection" id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False) video_id = db.Column(db.Integer, db.ForeignKey("videos.id"), nullable=False)
class Article(BaseModel, db.Model): __tablename__ = "info_article" id = db.Column(db.Integer, primary_key=True) # 文章编号 title = db.Column(db.String(256), nullable=False) # 文章标题 source_id = db.Column(db.Integer, db.ForeignKey('info_article_source.id')) # 文章来源 digest = db.Column(db.String(512), nullable=False) # 文章摘要 content = db.Column(db.Text, nullable=False) # 文章内容 clicks = db.Column(db.Integer, default=0) # 浏览量 index_image_url = db.Column(db.String(256)) # 文章列表图片路径 category_id = db.Column(db.Integer, db.ForeignKey("info_category.id")) # 文章分类 user_name = db.Column(db.String(25), default='张小强') status = db.Column(db.Integer, default=1) # 当前文章状态 如果为0代表审核通过,1代表审核中,-1代表审核不通过 reason = db.Column(db.String(256)) # 未通过原因,status = -1 的时候使用 # # 当前文章的所有评论 # comments = db.relationship("Comment", lazy="dynamic") def to_review_dict(self): # 发布状态查看 resp_dict = { "id": self.id, "title": self.title, "create_time": self.create_time.strftime("%Y-%m-%d %H:%M:%S"), "status": self.status, "reason": self.reason if self.reason else "" } return resp_dict def to_basic_dict(self): # 首页文章列表 resp_dict = { "id": self.id, "title": self.title, "source": self.source, "digest": self.digest, "create_time": self.create_time.strftime("%Y-%m-%d %H:%M:%S"), "index_image_url": self.index_image_url, "clicks": self.clicks, } return resp_dict def to_dict(self): # resp_dict = { "id": self.id, "title": self.title, "source": self.source, "digest": self.digest, "create_time": self.create_time.strftime("%Y-%m-%d %H:%M:%S"), "content": self.content, "clicks": self.clicks, "category": self.category.to_dict(), "index_image_url": self.index_image_url, "author": self.user_name, } return resp_dict
class CommentLike(BaseModel, db.Model): __tablename__ = "info_comment_like" comment_id = db.Column("comment_id", db.Integer, db.ForeignKey("info_comment.id"), primary_key=True) # 评论编号 user_id = db.Column("user_id", db.Integer, db.ForeignKey("info_user.id"), primary_key=True) # 用户编号
class ShopCar(db.Model): '''购物车表''' __tablename__ = "shop_car" user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True) # 用户id product_id = db.Column(db.Integer, db.ForeignKey('product.id'), primary_key=True) # 商品id nums = db.Column(db.Integer, default=1, nullable=False) # 数据库中的数量 is_remove = db.Column(db.INTEGER, default=0) # 是否移除 user = db.relationship('User', backref='shop_car') products = db.relationship("Product", backref='shop_car')
class CommentLike(BaseModel, db.Model): """评论点赞""" __tablename__ = 'info_comment_like' comment_id = db.Column('comment_id', db.Integer, db.ForeignKey('info_comment.id'), primary_key=True) # 评论编号 user_id = db.Column('user_id', db.Integer, db.ForeignKey('blog_customer.id'), primary_key=True) # 用户编号
class Product(BaseModel, db.Model): """商品""" __tablename__ = "product" id = db.Column(db.Integer, primary_key=True, nullable=False) # 商品id title = db.Column(db.String(255), nullable=False) # 商品标题 price = db.Column(db.INTEGER, nullable=False) # 商品价格 describe = db.Column(db.String(255), nullable=True) # 商品描述 category_id = db.Column(db.INTEGER, db.ForeignKey('category.c_id'), nullable=False) # 商品种类 all_nums = db.Column(db.INTEGER, nullable=False, default=0) # 商品数量 status = db.Column(db.INTEGER, nullable=False, default=2) # 商品状态:0上架中,1下架,2审核中 brand_id = db.Column(db.INTEGER, db.ForeignKey('brand.b_id'), nullable=False) # 品牌id seller_id = db.Column(db.INTEGER, db.ForeignKey('seller.id'), nullable=False) # 卖家id grade = db.Column(db.INTEGER, nullable=False, default=0) # 商品评分,默认是0 picture = db.Column(db.String(200)) # 商品图片 attrs = db.relationship('ProductSizeColor', backref='products', secondary='product_params') def to_dict(self): output_data_dict = { 'id': self.id, # 商品id 'title': self.title, # 商品标题 'price': self.price, # 商品价格 'describe': self.describe, # 商品描述 'category_id': self.category_id, # 商品种类 'all_nums': self.all_nums, # 商品数量 'status': self.status, # 商品状态:0上架中,1下架,2审核中 'brand_id': self.brand_id, # 品牌id 'seller_id': self.seller_id, # 卖家id 'grade': self.grade, # 商品评分,默认是0 'picture': self.picture, # 商品图片 } return output_data_dict def to_basic_dict(self): output_data_dict = { 'id': self.id, # 商品id 'title': self.title, # 商品标题 'price': self.price, # 商品价格 'grade': self.grade, # 商品评分,默认是0 'picture': self.picture, # 商品图片 } return output_data_dict def to_head_collect_dict(self): output_data_dict = { 'id': self.id, # 商品id 'title': self.title, # 商品标题 'price': self.price, # 商品价格 'picture': self.picture, # 商品图片 } return output_data_dict
class OrderForm(BaseModel, db.Model): """订单""" __tablename__ = "order_form" id = db.Column(db.Integer, primary_key=True, autoincrement=True, nullable=True) # 订单id user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False, primary_key=True) # 用户id address_id = db.Column(db.INTEGER, db.ForeignKey('shipping_address.id'), nullable=False, primary_key=True) # 地址id status = db.Column(db.INTEGER, nullable=False, default=0) # 定单状态,0代付款,1待发货,2待收货,3已签收,4已取消,-1未支付 payment_method = db.Column(db.INTEGER, nullable=False) # 付款方式,0支付宝,1银联,2ebay,3微信,-1未支付 products = db.relationship('Product', backref='order_form', secondary='order_product', lazy='dynamic') address = db.relationship('ShippingAddress', backref=db.backref('order_form', uselist=False))
class News(BaseModel, db.Model): """新闻""" __tablename__ = "info_news" id = db.Column(db.Integer, primary_key=True) # 新闻编号 title = db.Column(db.String(256), nullable=False) # 新闻标题 source = db.Column(db.String(64), nullable=False) # 新闻来源 digest = db.Column(db.String(512), nullable=False) # 新闻摘要 content = db.Column(db.Text, nullable=False) # 新闻内容 clicks = db.Column(db.Integer, default=0) # 浏览量 comments_count = db.Column(db.Integer, default=0) # 评论量 index_image_url = db.Column(db.String(256), default='') # 新闻列表图片路径 category_id = db.Column(db.Integer, db.ForeignKey("info_category.id")) user_id = db.Column(db.Integer, db.ForeignKey("info_user.id")) # 当前新闻的作者id status = db.Column(db.Integer, default=0) # 当前新闻状态 如果为0代表审核通过,1代表审核中,-1代表审核不通过 reason = db.Column(db.String(256)) # 未通过原因,status = -1 的时候使用 # 当前新闻的所有评论 comments = db.relationship("Comment", lazy="dynamic") def to_basic_dict(self): """将新闻对象信息转换为字典数据""" resp_dict = { "id": self.id, "title": self.title, "source": self.source, "digest": self.digest, "create_time": self.create_time.strftime("%Y-%m-%d %H:%M:%S"), "index_image_url": self.index_image_url, "clicks": self.clicks, # "category":self.category } return resp_dict def to_dict(self): """后台新闻审核详情页视图函数使用,data = {"news": news.to_dict()}""" resp_dict = { "id": self.id, "title": self.title, "source": self.source, "digest": self.digest, "create_time": self.create_time.strftime("%Y-%m-%d %H:%M:%S"), "index_image_url": self.index_image_url, "clicks": self.clicks, "category": self.category, "content": self.content } return resp_dict
class Comment(BaseModel, db.Model): """评论""" __tablename__ = 'info_comment' id = db.Column(db.Integer, primary_key=True) # 评论编号 user_id = db.Column(db.Integer, db.ForeignKey('blog_customer.id'), nullable=False) # 用户id articles_id = db.Column(db.Integer, db.ForeignKey('info_articles.id'), nullable=False) # 文章id content = db.Column(db.Text, nullable=False) # 评论内容 parent_id = db.Column(db.Integer, db.ForeignKey('info_comment.id')) # 父评论 parent = db.relationship('Comment', remote_side=[id]) # 自关联 like_count = db.Column(db.Integer, default=0) # 点赞次数
class AdOrder(db.Model, BaseModel): '''粉丝量到一定量然后广告接单''' __tablename__ = 'adorder' id = db.Column(db.Integer, primary_key=True, autoincrement=True) # 主键,自增长 agent_id = db.Column(db.Integer, db.ForeignKey('agent.id')) date_of_order = db.Column(db.DateTime, default=datetime.now) # 接单日 push_time = db.Column(db.DateTime) # 推送广告时间/可以写多个时间 ad_count = db.Column(db.Integer, nullable=False) # 广告数量 screenshots = db.Column(db.String(256)) # 截图 amount = db.Column(db.Integer) # 金额/单价 check_out_date = db.Column(db.DateTime) # 结算日 state = db.Column(db.Boolean, default=0, index=True) # 结算状态: 0表示未结算付款,1表示已结算付款 remark = db.Column(db.String(50)) # 备注 def __repr__(self): return '<AdOrder %r>' % self.id def to_dict(self): '''将对象转换为字典数据''' adorder_dict = { 'adorder_id': self.id, 'agent_id': self.agent_id, 'date_of_order': self.date_of_order, 'push_time': self.push_time, 'ad_count': self.ad_count, 'screenshots': self.screenshots, 'amount': self.amount, 'check_out_date': self.check_out_date, 'state': self.state, 'remark': self.remark, } return adorder_dict
class Articles(BaseModel, db.Model): """文章""" __tablename__ = 'info_articles' id = db.Column(db.Integer, primary_key=True) # 文章id title = db.Column(db.String(256), nullable=False) # 文章标题 source = db.Column(db.String(64)) # 文章来源 digest = db.Column(db.String(512), nullable=False) # 文章摘要 content = db.Column(db.Text, nullable=False) # 文章内容 clicks = db.Column(db.Integer, default=0) # 浏览量 tag = db.Column(db.String(64)) # 标签 index_image_url = db.Column(db.String(256)) # 文章列表图片路径 category_id = db.Column(db.Integer, db.ForeignKey('info_category.id')) # 文章分类 user_id = db.Column(db.Integer, db.ForeignKey('blog_customer.id')) # 文章作者 recommend = db.Column(db.Integer, default=0) # 推荐 comments = db.relationship('Comment', lazy='dynamic')
class CommentLike(BaseModel, db.Model): """ 评论点赞 BaseModel 继承 -- 实现创建时间和更新时间的补充 db.Model 数据模型 -- 实体和数据库表名建立关系 """ # 数据库表名 -- 和当前类绑定 __tablename__ = "info_comment_like" """ORM建立 属性 = 数据库字段""" comment_id = db.Column("comment_id", db.Integer, db.ForeignKey("info_comment.id"), primary_key=True) # 评论编号 user_id = db.Column("user_id", db.Integer, db.ForeignKey("info_user.id"), primary_key=True) # 用户编号
class ShippingAddress(BaseModel, db.Model): """收货地址""" __tablename__ = "shipping_address" id = db.Column(db.Integer, primary_key=True) # 收件地址id user_id = db.Column(db.Integer, db.ForeignKey('user.id')) # 用户编号 address = db.Column(db.String(100), nullable=False) # 地址 nickname = db.Column(db.String(20), nullable=False) # 收件人姓名 phoneNumber = db.Column(db.String(30), nullable=False) # 收件人手机号
class Adminlog(db.Model): '''管理员登录日志''' __tablename__ = "adminlog" id = db.Column(db.Integer, primary_key=True) # 编号 admin_id = db.Column(db.Integer, db.ForeignKey('admin.id')) # 所属管理员 ip = db.Column(db.String(100)) # 登录IP addtime = db.Column(db.DateTime, index=True, default=datetime.now) # 登录时间 def __repr__(self): return "<Adminlog %r>" % self.id
class HouseImage(BaseModel, db.Model): """房屋图片""" __tablename__ = "ih_house_image" id = db.Column(db.Integer, primary_key=True) house_id = db.Column(db.Integer, db.ForeignKey("ih_house_info.id"), nullable=False) # 房屋编号 url = db.Column(db.String(256), nullable=False) # 图片的路径
class Comment(BaseModel, db.Model): """评论""" __tablename__ = "info_comment" id = db.Column(db.Integer, primary_key=True) # 评论编号 user_id = db.Column(db.Integer, db.ForeignKey("info_user.id"), nullable=False) # 用户id news_id = db.Column(db.Integer, db.ForeignKey("info_news.id"), nullable=False) # 新闻id content = db.Column(db.Text, nullable=False) # 评论内容 comment_id = db.Column(db.Integer, db.ForeignKey("info_comment.id")) # 父评论id back_list = db.relationship('Comment', lazy='dynamic') #,backref='comment' like_count = db.Column(db.Integer, default=0) # 点赞条数 def to_dict(self): return { 'id': self.id, 'user': User.query.get(self.user_id).to_login_dict(), 'content': self.content, 'create_time': self.create_time.strftime('%Y-%m-%d %H:%M:%S'), 'like_count': self.like_count, 'backs': [ back.to_back_dict() for back in self.back_list.order_by(Comment.id.desc()) ], 'like': False } def to_back_dict(self): return { 'id': self.id, 'nick_name': User.query.get(self.user_id).nick_name, 'content': self.content }
class News(BaseModel, db.Model): """新闻""" __tablename__ = "info_news" id = db.Column(db.Integer, primary_key=True) # 新闻编号 title = db.Column(db.String(256), nullable=False) # 新闻标题 source = db.Column(db.String(64), nullable=False) # 新闻来源 digest = db.Column(db.String(512), nullable=False) # 新闻摘要 content = db.Column(db.Text, nullable=False) # 新闻内容 clicks = db.Column(db.Integer, default=0) # 浏览量 index_image_url = db.Column(db.String(256)) # 新闻列表图片路径 category_id = db.Column(db.Integer, db.ForeignKey("info_category.id")) user_id = db.Column(db.Integer, db.ForeignKey("info_user.id")) # 当前新闻的作者id status = db.Column(db.Integer, default=1) # 当前新闻状态 如果为0代表审核通过,1代表审核中,-1代表审核不通过 reason = db.Column(db.String(256)) # 未通过原因,status = -1 的时候使用 # 当前新闻的所有评论 comments = db.relationship("Comment", lazy="dynamic") def to_list_dict(self): return { "title":self.title, 'create_time':self.create_time, "status":self.status, "id":self.id } # 点击排行 def to_click_dict(self): return { 'id':self.id, 'title':self.title } # 新闻分类展示 def to_index_dict(self): return { 'id':self.id, 'title':self.title, # 'index_image_url':constants.QINIU_DOMIN_PREFIX+self.index_image_url, 'index_image_url':self.index_image_url, 'digest':self.digest, 'create_time':self.create_time, 'source':self.source }
class Subject(BaseModel, db.Model): """视频分类""" __tablename__ = "subject" id = db.Column(db.Integer, primary_key=True) # 分类编号 name = db.Column(db.String(64), nullable=False) # 分类名 cid = db.Column(db.Integer, db.ForeignKey("subject.id")) video_list = db.relationship('Videos', backref='subject', lazy='dynamic') def to_dict(self): resp_dict = {"id": self.id, "name": self.name, "cid": self.cid} return resp_dict
class Comment(BaseModel, db.Model): """ 评论 BaseModel 继承 -- 实现创建时间和更新时间的补充 db.Model 数据模型 -- 实体和数据库表名建立关系 """ # 数据库表名 -- 和当前类绑定 __tablename__ = "info_comment" """ORM建立 属性 = 数据库字段""" id = db.Column(db.Integer, primary_key=True) # 评论编号 user_id = db.Column(db.Integer, db.ForeignKey("info_user.id"), nullable=False) # 用户id news_id = db.Column(db.Integer, db.ForeignKey("info_news.id"), nullable=False) # 新闻id content = db.Column(db.Text, nullable=False) # 评论内容 parent_id = db.Column(db.Integer, db.ForeignKey("info_comment.id")) # 父评论id parent = db.relationship("Comment", remote_side=[id]) # 自关联 like_count = db.Column(db.Integer, default=0) # 点赞条数 def to_dict(self): """ 把对象数据转换为字典数据 """ # 封装字典 resp_dict = { "id": self.id, "create_time": self.create_time.strftime("%Y-%m-%d %H:%M:%S"), "content": self.content, "parent": self.parent.to_dict() if self.parent else None, "user": User.query.get(self.user_id).to_dict(), "news_id": self.news_id, "like_count": self.like_count } # 返回字典 return resp_dict
class Comment(BaseModel, db.Model): """评论""" __tablename__ = "info_comment" id = db.Column(db.Integer, primary_key=True) # 评论编号 user_id = db.Column(db.Integer, db.ForeignKey("info_user.id"), nullable=False) # 用户id news_id = db.Column(db.Integer, db.ForeignKey("info_news.id"), nullable=False) # 新闻id content = db.Column(db.Text, nullable=False) # 评论内容 parent_id = db.Column(db.Integer, db.ForeignKey("info_comment.id")) # 父评论id # parent = db.relationship("Comment", remote_side=[id]) # 自关联 backs_list=db.relationship('Comment',lazy='dynamic') #,backref='parent', # remote_side=['parent_id'] like_count = db.Column(db.Integer, default=0) # 点赞条数 def to_dict(self): user = User.query.get(self.user_id) return { "id": self.id, "create_time": self.create_time.strftime("%Y-%m-%d %H:%M:%S"), "content": self.content, 'user': user.to_login_dict(), "news_id": self.news_id, "like_count": self.like_count, # 回复 'backs': [back.to_back_dict() for back in self.backs_list], # 是否点赞 'is_like': False } def to_back_dict(self): user = User.query.get(self.user_id) return { "id":self.id, "nick_user":user.nick_name, "content":self.content }
class Comment(BaseModel, db.Model): """评论""" __tablename__ = "comment" id = db.Column(db.Integer, primary_key=True) # 评论编号 content = db.Column(db.Text, nullable=False) # 评论内容 parent_id = db.Column(db.Integer, db.ForeignKey("comment.id")) # 父评论id parent = db.relationship("Comment", remote_side=[id]) # 自关联 user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False) # 用户id class_id = db.Column(db.Integer, db.ForeignKey("videos.id"), nullable=False) # 视频id def to_dict(self): resp_dict = { "id": self.id, "create_time": self.create_time.strftime("%Y-%m-%d %H:%M:%S"), "content": self.content, "parent": self.parent.to_dict() if self.parent else None, "user": User.query.get(self.user_id).to_dict(), "video_id": self.class_id } return resp_dict
class Admin(db.Model): '''管理员''' __tablename__ = "admin" id = db.Column(db.Integer, primary_key=True) # 编号 name = db.Column(db.String(100), unique=True) # 管理员账号 pwd = db.Column(db.String(100)) # 管理员密码 is_super = db.Column(db.SmallInteger) # 是否为超级管理员,0为超级管理员 role_id = db.Column(db.Integer, db.ForeignKey('role.id')) # 所属角色 addtime = db.Column(db.DateTime, index=True, default=datetime.now) # 添加时间 adminlogs = db.relationship("Adminlog", backref='admin') # 管理员登录日志外键关系关联 oplogs = db.relationship("Oplog", backref='admin') # 管理员操作日志外键关系关联 def __repr__(self): return "<Admin %r>" % self.name def check_pwd(self, pwd): from werkzeug.security import check_password_hash return check_password_hash(self.pwd, pwd)
class Category(BaseModel, db.Model): __tablename__ = "info_category" id = db.Column(db.Integer, primary_key=True) # 分类编号 name = db.Column(db.String(64), nullable=False) # 分类名 parent_id = db.Column(db.Integer, db.ForeignKey("info_category.id")) # 父分类id parent = db.relationship("Category", remote_side=[id]) # 自关联 article_list = db.relationship('Article', backref='category', lazy='dynamic') def to_dict(self): resp_dict = { "id": self.id, "name": self.name, "parent_id": self.parent_id } return resp_dict
class Stat(db.Model, BaseModel): '''代理申请通过审核后加粉统计''' __tablename__ = 'stat' id = db.Column(db.Integer, primary_key=True, autoincrement=True) # 主键,自增长 agent_id = db.Column(db.Integer, db.ForeignKey('agent.id')) today_fans = db.Column(db.Integer, nullable=False) # 当天加粉数 total_fans = db.Column(db.Integer) # 累计粉丝数 def __repr__(self): return '<Stat %r>' % self.total_fans def to_dict(self): '''将对象转换为字典数据''' stat_dict = { 'stat_id': self.id, 'agent_id': self.agent_id, 'create_time': self.create_time.strftime('%Y-%m-%d %H:%M:%S'), 'today_fans': self.today_fans, 'total_fans': self.total_fans, } return stat_dict
class Videos(BaseModel, db.Model): """视频表""" __tablename__ = "videos" id = db.Column(db.Integer, primary_key=True) intro = db.Column(db.String(60), nullable=False) # 简介 url = db.Column(db.String(256)) # 视频地址 clicks = db.Column(db.Integer, default=0) # 播放次数 img_url = db.Column(db.String(256), nullable=False) # 封面 subject_id = db.Column(db.Integer, db.ForeignKey("subject.id"), nullable=False) # 分类id def to_dict(self): rep_dict = { "id": self.id, "intro": self.intro, "img_url": self.img_url, "url": self.url, "clicks": self.clicks, "subject": Subject.query.get(self.subject_id).to_dict(), "create_time": self.create_time } return rep_dict