class RoomType(db.Model): __tablename__ = 'room_type' id = db.Column(db.INTEGER,primary_key=True) r_id = db.Column(db.INTEGER,db.ForeignKey('roominfo_main.room_id')) type = db.Column(db.Enum('PC游戏','主机游戏','手机游戏','户外美食','娱乐','其它')) def __init__(self,rid,type): self.r_id = rid self.type = type
class UserFav(db.Model): __tablename__ = 'user_fav' id = db.Column(db.INTEGER,primary_key=True) uid = db.Column(db.INTEGER,db.ForeignKey('userinfo_main.user_id')) fav = db.Column(db.INTEGER,unique=True) def __init__(self,uid,fav): self.uid = uid self.fav = fav
class UserScore(db.Model): __tablename__ = 'user_score' id = db.Column(db.INTEGER,primary_key=True) u_id = db.Column(db.INTEGER, db.ForeignKey('userinfo_main.user_id')) score = db.Column(db.INTEGER) def __init__(self,uid,score): self.u_id = uid self.score = score
class VideoList(db.Model): # __table__ == 'videolist' id = db.Column(db.INTEGER,primary_key=True) rid = db.Column(db.INTEGER,db.ForeignKey('roominfo_main.room_id')) video_url = db.Column(db.String(128)) poster_url = db.Column(db.String(128)) video_name = db.Column(db.String(64)) def __init__(self,rid,v_url,p_url,v_name): self.rid = rid self.video_url = v_url self.poster_url = p_url self.video_name = v_name
class RoomComment(db.Model): # __tablename__ == 'room_comment' id = db.Column(db.INTEGER,primary_key=True) rid = db.Column(db.INTEGER,db.ForeignKey('roominfo_main.room_id')) uid = db.Column(db.INTEGER) comment = db.Column(db.Text) uname = db.Column(db.String(30)) def __init__(self,rid,comment,uid,uname): self.rid = rid self.comment = comment self.uid = uid self.uname = uname
class RoomGift(db.Model): __tablename__ = 'roominfo_gift' id = db.Column(db.INTEGER,primary_key=True) r_id = db.Column(db.INTEGER,db.ForeignKey('roominfo_main.room_id')) free = db.Column(db.INTEGER) low = db.Column(db.INTEGER) middle = db.Column(db.INTEGER) highclass = db.Column(db.INTEGER) def __init__(self,r_id,free,low,middle,high): self.r_id = r_id self.free = free self.low = low self.middle = middle self.high = high
class RoomCount(db.Model): __tablename__ = 'roominfo_count' id = db.Column(db.INTEGER,primary_key=True) r_id = db.Column(db.INTEGER,db.ForeignKey('roominfo_main.room_id')) host_lv = db.Column(db.INTEGER) fans_num = db.Column(db.INTEGER) exp = db.Column(db.INTEGER) p_count = db.Column(db.INTEGER) def __init__(self,r_id,lv,fans,exp,pco): self.r_id = r_id self.host_lv = lv self.fans_num = fans self.exp = exp self.p_count = pco
class UserOther(db.Model): __tablename__ = 'user_other_info' id = db.Column(db.INTEGER,primary_key=True) uid = db.Column(db.INTEGER,db.ForeignKey('userinfo_main.user_id')) sex = db.Column(db.Enum('男','女','保密'),nullable=True) phone = db.Column(db.String(11),nullable=True) city = db.Column(db.String(15),nullable=True) ps = db.Column(db.Text,nullable=True) def __init__(self,uid,sex,phone,city,ps): self.uid = uid self.sex = sex self.phone = phone self.city = city self.ps = ps
class UserGift(db.Model): __tablename__ = 'userinfo_gift' id = db.Column(db.INTEGER,primary_key=True) u_id = db.Column(db.INTEGER, db.ForeignKey('userinfo_main.user_id')) free = db.Column(db.INTEGER) low = db.Column(db.INTEGER) middle = db.Column(db.INTEGER) highclass = db.Column(db.INTEGER) def __init__(self,u_id,free,low,middle,high): self.u_id = u_id self.free = free self.low = low self.middle = middle self.high = high
class RoomMain(db.Model): __tablename__ = 'roominfo_main' room_id = db.Column(db.INTEGER,primary_key=True) room_name = db.Column(db.String(100)) host_name = db.Column(db.String(50)) img = db.Column(db.String(128)) is_oline = db.Column(db.INTEGER) live_url = db.Column(db.String(128)) host_img = db.Column(db.String(128)) count = db.relationship('RoomCount',backref='roominfo_main',lazy='dynamic') gift = db.relationship('RoomGift',backref='roominfo_main',lazy='dynamic') type = db.relationship('RoomType',backref='roominfo_main',lazy='dynamic') comment = db.relationship('RoomComment',backref='roominfo_main',lazy='dynamic') videolist = db.relationship('VideoList',backref='roominfo_main',lazy='dynamic') def __init__(self,rname,hname,img,ol,url,himg='img/user.jpg'): self.room_name = rname self.host_name = hname self.img = img self.is_oline = ol self.live_url = url self.host_img = himg
class UserMain(UserMixin,db.Model): __tablename__ = 'userinfo_main' user_id = db.Column(db.INTEGER,primary_key=True) user_name = db.Column(db.String(20),nullable=False,unique=True) u_passwd = db.Column(db.String(256),nullable=False) age = db.Column(db.INTEGER,nullable=False) email = db.Column(db.String(50),nullable=False) img = db.Column(db.String(128)) other = db.relationship('UserOther',backref='userinfo_main',lazy='dynamic') fav = db.relationship('UserFav',backref='useinfo_main',lazy='dynamic') gift = db.relationship('UserGift',backref='userinfo_main',lazy='dynamic') score = db.relationship('UserScore',backref='userinfo_main',lazy='dynamic') def __init__(self,uname,pwd,age,email,img='img/user.jpg'): self.user_name = uname self.u_passwd = pwd self.age = age self.email = email self.img = img def __repr__(self): return 'userinfo %s %s'%(self.user_name,self.u_passwd)