class User(db.Model): __tablename__ = 'User' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(20), nullable=True) age = db.Column(db.Integer, nullable=True) phone = db.Column(db.String(30), nullable=True) city = db.Column(db.String(30), nullable=True)
class Blog(db.Model): '''初始化微博功能表''' __tablename__ = 'blog' wid = db.Column(db.Integer, primary_key=True, unique=True) content = db.Column(db.Text, nullable=False) lasttime = db.Column(db.DateTime) thumb = db.Column(db.Integer,default=0) username = db.Column(db.String(20), nullable=False) @property def author(self): return User.query.filter_by(username=self.username).one() @classmethod def fake_weibos(cls, username_list, num): wb_list = [] for i in range(num): year = random.randint(2010, 2019) month = random.randint(1, 12) day = random.randint(1, 28) date = '%04d-%02d-%02d' % (year, month, day) username = random.choice(username_list) content = random_word(random.randint(70, 140)) wb = cls(username=username, content=content, lasttime=date) wb_list.append(wb) db.session.add_all(wb_list) db.session.commit()
class User(db.Model): """创建User表格""" __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(10), nullable=False, unique=True) password = db.Column(db.String(128), nullable=False) gender = db.Column(db.Enum('男', '女'), default='男') city = db.Column(db.String(20), default='上海') phone = db.Column(db.String(20)) create_time = db.Column(db.DateTime) avatar = db.Column(db.String(256), default='/static/img/default.png') follows = db.Column(db.Integer, nullable=False, default=0) fans = db.Column(db.Integer, nullable=False, default=0) #创建随机用户 @classmethod def fake_users(cls, num): users = [] for i in range(num): username = random_zh_str(3) password = '******' gender = random.choice(['男', '女']) phone = '123456789' create_time = '2000-01-21' user = cls(username=username, password=password, gender=gender, phone=phone, create_time=create_time) users.append(user) db.session.add_all(users) db.session.commit() return users
class Article(db.Model): __tablename__ = 'article' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(20), nullable=False) content = db.Column(db.Text, nullable=False) created_time = db.Column(db.DateTime)
class Weibo(db.Model): __tablename__ = 'weibo' id = db.Column(db.Integer, primary_key=True) uid = db.Column(db.Integer, nullable=False, index=True) content = db.Column(db.Text, nullable=False) create_time = db.Column(db.DateTime, nullable=False) update_time = db.Column(db.DateTime, nullable=False) @property def author(self): '''获取当前微博的作者''' user = User.query.get(self.uid) return user @classmethod def fake_weibo(cls, uid_list, num): wb_list = [] for i in range(num): year = random.randint(2009, 2019) month = random.randint(1, 12) day = random.randint(1, 28) date = '%04d-%02d-%02d' % (year, month, day) uid = random.choice(uid_list) content = random_hz_str(random.randint(80, 120)) wb = cls(uid=uid, content=content, create_time=date, update_time=date) wb_list.append(wb) db.session.add_all(wb_list) db.session.commit()
class Discuss(db.Model): __tablename__ = 'discuss' id = db.Column(db.Integer, primary_key=True) uname = db.Column(db.String(10)) pname = db.Column(db.String(10)) words = db.Column(db.Text, nullable=False) date = db.Column(db.Date)
class Follow(db.Model): __tablename__ = 'follow' #自己跟随的用用户的id fid = db.Column(db.Integer, nullable=False, primary_key=True) #自己的id uid = db.Column(db.Integer, nullable=False, primary_key=True)
class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) password = db.Column(db.String(128), nullable=False) # 为了存储加密后的密码,所以长一点 city = db.Column(db.String(10), default='中国') phone = db.Column(db.String(16))
class Weibo(db.Model): __tablename__ = 'weibo' id = db.Column(db.Integer, primary_key=True) uid = db.Column(db.Integer, nullable=False, index=True) content = db.Column(db.Text, nullable=False) created = db.Column(db.DateTime, nullable=False) updated = db.Column(db.DateTime, nullable=False)
class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20)) password = db.Column(db.String(128)) city = db.Column(db.String(10)) phone = db.Column(db.String(16))
class Article(db.Model): __tablename__ = 'article' id = db.Column(db.Integer, primary_key=True) uid = db.Column(db.Integer, nullable=False) # 发表者id article = db.Column(db.String(300)) created = db.Column(db.DateTime, nullable=False) # 发表微博时间 changed = db.Column(db.DateTime, nullable=False) # 修改微博时间
class Pro(db.Model): __tablename__ = 'pro' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(20), nullable=False, unique=True) uname = db.Column(db.String(10)) article = db.Column(db.Text, default='请写点什么') date = db.Column(db.Date)
class Article(db.Model): '''初始化article表''' __tablename__ = 'article' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), nullable=False) title = db.Column(db.String(20), nullable=False) content = db.Column(db.Text, nullable=False) date = db.Column(db.DateTime)
class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(10), unique=True, nullable=False) password = db.Column(db.String(128), nullable=False) head = db.Column(db.String(128), default='default.jpg') gender = db.Column(db.Enum('男', '女', '保密'), default='保密') n_fans = db.Column(db.Integer, default=0) birthday = db.Column(db.Date, default='1997-2-10') city = db.Column(db.String(20), default='(暂未填写)') reg_time = db.Column(db.DateTime, default=datetime.now()) @classmethod def make_users(cls, num): users = [] for i in range(num): user = cls() y = random.randint(2000, 2018) m = random.randint(1, 12) d = random.randint(1, 28) user.reg_time = '%04d-%02d-%02d' % (y, m, d) user.name = random_zh_str(3) user.password = make_password('123456') users.append(user) if session_add_all(users): print('多条测试用户信息创建成功!!!') else: print('多条测试用户信息创建失败!!!') return users
class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(30), unique=True) password = db.Column(db.String(128), nullable=False) gender = db.Column(db.Enum('male', 'female', 'unknow'), default='unknow') birthday = db.Column(db.Date, default='2000-01-01') phone = db.Column(db.String(15)) location = db.Column(db.String(10), default='中国') user_image = db.Column(db.String(256), default='/static/img/default.png') description = db.Column(db.Text, default='') register_time = db.Column(db.DateTime, nullable=False) # 用户注册时间
class Users(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), nullable=False, unique=True) password = db.Column(db.String(128), nullable=False) tel = db.Column(db.String(20), nullable=False) birthday = db.Column(db.Date, default='1960-01-01') gender = db.Column(db.Enum('male', 'female')) avatar = db.Column(db.String(256), default='/static/img/default.jpg') created = db.Column(db.DateTime, nullable=False) n_follow = db.Column(db.Integer, nullable=False, default=0) n_fan = db.Column(db.Integer, nullable=False, default=0)
class User(db.Model): __tablename__ = 'user' # 类变量定义在数据库中表的名字 id = db.Column(db.Integer, primary_key=True) nickname = db.Column(db.String(20), unique=True) password = db.Column(db.String(128), nullable=False) gender = db.Column(db.Enum('male', 'female', 'unknow'), default='unknow') birthday = db.Column(db.Date, default='1990-01-01') city = db.Column(db.String(10), default='中国') avatar = db.Column(db.String(256), default='/static/img/default.png') bio = db.Column(db.Text, default='') create = db.Column(db.DateTime, nullable=False) # 用户注册时间
class Microblog(db.Model): __tablename__ = 'microblog' id = db.Column(db.Integer, primary_key=True) uid = db.Column(db.Integer, nullable=False) #与user表里面的id对应 content = db.Column(db.Text, nullable=False) issued = db.Column(db.DateTime, nullable=False) updated = db.Column(db.DateTime, nullable=False) @property def author(self): '''获取当前微博的作者''' user = User.query.get(self.uid) return user #使用举例:weibo = Microblog() # weibo.author.name 微博作者的姓名 #weibo.author.location 微博作者的地方
class Idol(db.Model): __tablename__ = 'idol' idol_id = db.Column(db.Integer, primary_key=True) fans_id = db.Column(db.Integer, primary_key=True) @classmethod def idol_list(cls, uid): idols = Idol.query.filter_by(fans_id=uid).all() idol_l = [idol.idol_id for idol in idols] return idol_l @classmethod def fans_list(cls, idol_id): fans = Idol.query.filter_by(idol_id=idol_id).all() fans_l = [fen.fans_id for fen in fans] fans_user_l = User.query.filter(User.id.in_(fans_l)) return fans_user_l
class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) nickname = db.Column(db.String(20), unique=True) password = db.Column(db.String(128), nullable=False) gender = db.Column(db.Enum('male', 'female', 'unknow'), default='unknow') birthday = db.Column(db.Date, default='2000-01-01') city = db.Column(db.String(10), default='中国') bio = db.Column(db.Text, default='') created = db.Column(db.DateTime, nullable=False)
class User(db.Model): __tablename__ = 'user_info' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(10), unique=True, nullable=False) password = db.Column(db.String(16), nullable=False) gender = db.Column(db.Enum('男', '女'), default='男') age = db.Column(db.Integer, default=24) city = db.Column(db.String(20), default='上海') phone = db.Column(db.String(16))
class Article(db.Model): __tablename__ = 'article' id = db.Column(db.Integer, primary_key=True) uid = db.Column(db.Integer, nullable=False, index=True) content = db.Column(db.Text, nullable=False) created = db.Column(db.DateTime, nullable=False) updated = db.Column(db.DateTime, nullable=False) n_thumb = db.Column(db.Integer, nullable=False, default=0) @property def author(self): """获取当前微博的作者""" return User.query.get(self.uid) @classmethod def fake_article(cls, uid_list, num): art_list = [] for i in range(num): year = random.randint(2010, 2019) month = random.randint(1, 12) day = random.randint(1, 28) date = '%04d-%02d-%02d' % (year, month, day) uid = random.choice(uid_list) content = random_zh_str(random.randint(70, 140)) art = cls(uid=uid, content=content, created=date, updated=date) art_list.append(art) db.session.add_all(art_list) db.session.commit()
class Article(db.Model): __tablename__ = 'article' id = db.Column(db.Integer, primary_key=True) uid = db.Column(db.Integer, nullable=False, index=True) content = db.Column(db.Text,nullable=False) created = db.Column(db.DateTime, nullable=False) updated = db.Column(db.DateTime, nullable=False) n_thumb = db.Column(db.Integer, nullable=False, default=0) @property def author(self): # 我这定义的是啥 是个实例方法 '''获取微博的作者''' return User.query.get(self.uid) # 谁调用 self 就指谁 # 返回的是一个 Basequery 对象 # 凭什么在这里可以去到用户名,因为微博在创建的时候写入了 作者的uid,我们用 实例.uid 可以获得用户的id # 再拿这个id 去用户的信息,进而能取到用户的名字 @classmethod def fake_weibos(cls, uid_list, num): wb_list = [] for i in range(num): year = random.randint(2010, 2019) month = random.randint(1, 12) day = random.randint(1, 28) date = '%04d-%02d-%02d' % (year, month, day) uid = random.choice(uid_list) content = random_zh_str(random.randint(70, 140)) wb = cls(uid=uid, content=content, created=date, updated=date) wb_list.append(wb) db.session.add_all(wb_list) db.session.commit()
class User(db.Model): '''添加用户表''' __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) password = db.Column(db.String(20), nullable=False) gender = db.Column(db.Enum('男', '女', '保密')) city = db.Column(db.String(20)) n_follow = db.Column(db.Integer, nullable=False, index=True, default=0) n_fans = db.Column(db.Integer, nullable=False, index=True, default=0)
class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), nullable=False, unique=True) password = db.Column(db.String(128)) phone = db.Column(db.String(20), nullable=False, unique=True) gender = db.Column(db.Enum('男', '女', '保密')) city = db.Column(db.String(10))
class Hudong(db.Model): __tablename__ = 'hudong' id = db.Column(db.Integer, primary_key=True) aname = db.Column(db.String(20)) eid = db.Column(db.Integer) cont = db.Column(db.Text) hid = db.Column(db.Integer) hname = db.Column(db.String(20))
class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) password = db.Column(db.String(128), nullable=False) gender = db.Column(db.Enum('male', 'female', 'unknow'), default='unknow') city = db.Column(db.String(10), default='上海') @classmethod def fake_users(cls, num): users_list = [] for i in range(num): username = random_hz_str(random.choice([2, 3, 4])) password = '******' gender = random.choice(['male', 'female', 'unknow']) city = random.choice(['旧金山', '北京', '纽约', '东京']) user = cls(username=username, password=password, gender=gender, city=city) users_list.append(user) db.session.add_all(users_list) db.session.commit() return users_list
class Wb(db.Model): '''添加微博表''' __tablename__ = 'wb' id = db.Column(db.Integer, primary_key=True) u_id = db.Column(db.Integer, nullable=False, index=True) u_name = db.Column(db.String(20), nullable=False) n_thumb = db.Column(db.Integer, nullable=False, index=True, default=0) wbtime = db.Column(db.DateTime, nullable=False) wbcontent = db.Column(db.Text, nullable=False)
class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) nickname = db.Column(db.String(20), unique=True) password = db.Column(db.String(128), nullable=False) birthday = db.Column(db.Date,default='2000-01-01')\ follow_num = db.Column(db.Integer, nullable=False, default=0) fans_num = db.Column(db.Integer, nullable=False, default=0)
class Essay(db.Model): __tablename__ = 'essay' id = db.Column(db.Integer, primary_key=True) nickname = db.Column(db.String(20)) cont = db.Column(db.Text) created = db.Column(db.DateTime, nullable=False) updated = db.Column(db.DateTime, nullable=False) thumb_num = db.Column(db.Integer, nullable=False, default=0)