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): """创建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 User(db.Model): '''初始化用户表''' __tablename__ = 'users' uid = 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('男', '女', '保密'), default='保密') phone = db.Column(db.String(16), unique=True, nullable=False) city = db.Column(db.String(16), nullable=False, default='暂无') photo = db.Column(db.String(128), default='/static/img/default') hobbit = db.Column(db.String(20), nullable=False, default='暂无') des = db.Column(db.Text, nullable=False, default='暂无') follow = db.Column(db.Integer, nullable=False, default=0) fans = db.Column(db.Integer, nullable=False, default=0) @classmethod def fake_users(cls, num): users = [] phone = 13555879797 for i in range(num): username = '******' + str(random.randint(100, 999)) password = '******' phone = phone + 1 gender = random.choice(['男', '女', '保密']) user = cls(username=username, password=password, gender=gender, phone=phone) users.append(user) db.session.add_all(users) db.session.commit() return users
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 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 User(db.Model): ''' 初始化用户信息表 ''' __tablename__ = 'users' uid = 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('男','女','保密'), default='保密') phone = db.Column(db.String(16), unique=True, nullable=False) photo = db.Column(db.Boolean,default=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) 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 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' 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) 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) username = db.Column(db.String(20), unique=True) password = db.Column(db.String(128)) gender = db.Column(db.Enum('男', '女', '保密')) birthday = db.Column(db.DateTime) city = db.Column(db.String(10)) address = db.Column(db.String(64)) phone = db.Column(db.String(16)) # 为什么要在这里创建 创造用户的函数 我现在还不是很清楚呢,但创建的是一个类方法 @classmethod def fake_users(cls, num): users = [] # 下面就要开始创建用户信息了,创建多少个我们用for循环来控制 for i in range(num): year = random.randint(1980, 2002) month = random.randint(1, 12) day = random.randint(1, 28) username = random_zh_str(3) password = '******' gender = random.choice(['男', '女', '保密']) birthday = '%04d-%02d-%02d' % (year, month, day) city = random.choice(['上海', '北京', '广州', '深圳', '池州', '安庆', '马鞍山']) address = random_zh_str(6) #phone = random.sample([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 6) phone = make_num() user = cls(username=username, password=password, gender=gender, birthday=birthday, city=city, address=address, phone=phone) users.append(user) # 执行添加数据 db.session.add_all(users) db.session.commit() return users
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='上海') avatar = db.Column(db.String(256), default='/static/img/default.png') bio = db.Column(db.Text, dafault="") created = db.Column(db.DateTime, nullable=False) # 用户注册时间 @classmethod def fake_users(cls, num): users = [] for i in range(num): year = random.randint(1980, 2000) month = random.randint(1, 12) day = random.randint(1, 28) nickname = random_zh_str(3) password = '******' gender = random.choice(['male', 'female', 'unknow']) birthday = '%04d-%02d-%02d' % (year, month, day) city = random.choice( ['上海', '苏州', '长沙', '合肥', '呼和浩特', '青岛', '大理', '铁岭']) bio = random_zh_str(30) created = '2018-07-19' user = cls(nickname=nickname, password=password, gender=gender, birthday=birthday, city=city, bio=bio, created=created) users.append(user) db.session.add_all(users) db.session.commit() return users
class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) username = 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='中国') avatar = db.Column(db.String(256), default='/static/img/default.png') bio = db.Column(db.Text, default='') created = db.Column(db.DateTime, nullable=False) n_follow = db.Column(db.Integer, nullable=False, default=0) n_fans = db.Column(db.Integer, nullable=False, default=0) @classmethod def fake_users(cls, num): users = [] for i in range(num): year = random.randint(2010, 2019) month = random.randint(1, 12) day = random.randint(1, 28) username = random_zh_str(3) password = '******' gender = random.choice(['male', 'female', 'unknow']) birthday = '%04d-%02d-%02d' % (year, month, day) city = random.choice(['上海', '苏州', '长沙', '哈尔滨', '长春', '北京']) bio = random_zh_str(30) created = '2010-02-28' user = cls(username=username, password=password, gender=gender, birthday=birthday, city=city, bio=bio, created=created)
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