class Moviecol(db.Model): __tablename__ = 'moviecol' id = db.Column(db.Integer, primary_key=True) # 编号 movie_id = db.Column(db.Integer, db.ForeignKey('movie.id')) # 所属电影 user_id = db.Column(db.Integer, db.ForeignKey('user.id')) # 所属用户 add_time = db.Column(db.DateTime, index=True, default=datetime.now) # 添加时间 def __str__(self): return 'Comment %r' % self.id
class Posts(db.Model): __tablename__ = 'posts' id = db.Column(db.Integer, primary_key=True, autoincrement=True) rid = db.Column(db.Integer, index=True, default=0) content = db.Column(db.Text) pub_time = db.Column(db.DateTime, default=datetime.utcnow) uid = db.Column(db.Integer, db.ForeignKey('users.id')) author = db.relationship('User', backref="postes")
class UserLog(db.Model): __tablename__ = 'userlog' id = db.Column(db.Integer, primary_key=True) # 编号 user_id = db.Column(db.Integer, db.ForeignKey('user.id')) # 关联会员 ip = db.Column(db.String(100)) # 登陆IP add_time = db.Column(db.DateTime, index=True, default=datetime.now) # 登陆时间 def __str__(self): return '<UserLog %r>' % self.id
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 add_time = db.Column(db.DateTime, index=True, default=datetime.now) # 登陆时间 def __str__(self): return '<AdminLog %r>' % self.id
class Posts(db.Model): __tablename__ = 'posts' id = db.Column(db.Integer, primary_key=True, autoincrement=True) rid = db.Column(db.Integer, index=True, default=0) content = db.Column(db.Text) pub_time = db.Column(db.DateTime, default=datetime.utcnow) uid = db.Column(db.Integer, db.ForeignKey("users.id")) author = db.relationship("User", backref="postes") def __repr__(self): return 'Posts:id:%d' % self.id
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, default=0) # 是否蔚超级管理员,1为超级管理员 role_id = db.Column(db.Integer, db.ForeignKey('role.id')) # 所属角色 add_time = db.Column(db.DateTime, index=True, default=datetime.now) # 添加时间 adminlog = db.relationship('AdminLog', backref='admin') # 登陆日志外键关联 oplog = db.relationship('OpLog', backref='admin') # 操作日志外键关联 def check_pwd(self, pwd): from werkzeug.security import check_password_hash return check_password_hash(self.pwd, pwd) def __str__(self): return '<Admin %r>' % self.id
class Movie(db.Model): __tablename = 'movie' id = db.Column(db.Integer, primary_key=True) # 编号 title = db.Column(db.String(255), unique=True) # 标题 url = db.Column(db.String(255), unique=True) # 地址 info = db.Column(db.Text) # 简介 logo = db.Column(db.String(255), unique=True) # 封面 star = db.Column(db.SmallInteger) # 星级 playnum = db.Column(db.BigInteger, default=0) # 播放量 commentnum = db.Column(db.BigInteger, default=0) # 评论量 tag_id = db.Column(db.Integer, db.ForeignKey('tag.id')) # 所属标签 area = db.Column(db.String(255)) # 上映地区 release_time = db.Column(db.Date) # 上映时间 length = db.Column(db.String(100)) # 播放时间 add_time = db.Column(db.DateTime, index=True, default=datetime.now) # 添加时间 comment = db.relationship('Comment', backref='movie') # 评论外键关联 moviecol = db.relationship('Moviecol', backref='movie') # 收藏外键关联 def __str__(self): return '<Movie %r>' % self.title
from .users import User from .posts import Posts from apps.exts import db collections = db.Table( 'collections', db.Column('user_id', db.Integer, db.ForeignKey('users.id')), db.Column('posts_id', db.Integer, db.ForeignKey('posts.id')), )