예제 #1
0
파일: models.py 프로젝트: HuZongHan/weibo
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('男', '女', '保密'), default='unknown')
    city = db.Column(db.String(10), default='中国')
    avatar = db.Column(db.String(256), default='/static/img/default.png')
    birthday = db.Column(db.Date, default='')
    bio = db.Column(db.Text, default='')
    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
예제 #2
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='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(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 = '2013-11-12'
            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
예제 #3
0
파일: models.py 프로젝트: Cheng-ning/weibo
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)
예제 #4
0
파일: models.py 프로젝트: fa00fa/-
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
예제 #5
0
파일: models.py 프로젝트: luoyibei/Weibo
class Comment(db.Model):
    '''添加评论表'''
    __tablename__ = 'comment'

    id = db.Column(db.Integer, primary_key=True)
    u_name = db.Column(db.String(20), nullable=False, index=True)
    w_id = db.Column(db.Integer, nullable=False, index=True)
    c_id = db.Column(db.Integer, nullable=False, index=True, default=0)
    cmcontent = db.Column(db.Text, nullable=False)
    cmtime = db.Column(db.DateTime, nullable=False)

    @property
    def upper(self):
        if self.c_id == 0:
            return None
        else:
            return Comment.query.get(self.c_id)
예제 #6
0
class Weibo(db.Model):
    __tablename__ = 'weibo'
    
    id = db.Column(db.Integer, primary_key=True)
    uid = db.Column(db.Integer, index=True, nullable=False)
    content = db.Column(db.Text, nullable=False)
    filename = db.Column(db.String(256))
    zan_num = db.Column(db.Integer, default=0)
    public = db.Column(db.Boolean, default=True)  # 默认公开
    cr_time = db.Column(db.DateTime)
    up_time = db.Column(db.DateTime)
    
    @property
    def zan_list(self):
        thumbs = Thumb.query.filter_by(wid=self.id).all()
        z_list = [thumb.uid for thumb in thumbs]
        return z_list
    
    @property
    def fans_list(self):
        fans = Idol.query.filter_by(idol_id=self.uid).all()
        fen_list = [fen.fans_id for fen in fans]
        return fen_list
    
    @classmethod
    def make_weibo(cls, num, list):
        weibos = []
        for i in range(num):
            weibo = cls()
            y = random.randint(2010, 2018)
            m = random.randint(1, 12)
            d = random.randint(1, 28)
            
            weibo.uid = random.choice(list).id
            weibo.content = random_zh_str(random.randint(50, 140))
            weibo.cr_time = weibo.up_time = '%04d-%02d-%02d' % (y, m, d)
            
            weibos.append(weibo)
        if session_add_all(weibos):
            print('微博测试数据创建成功!!!')
        else:
            print('微博测试数据创建失败!!!')
예제 #7
0
파일: models.py 프로젝트: xyj228/weibo
class Back(db.Model):
    __tablename__ = 'back'
    id = db.Column(db.Integer, primary_key=True)
    uname = db.Column(db.String(10))
    backwords = db.Column(db.Text, nullable=False)
    date = db.Column(db.Date)
예제 #8
0
class WEB(db.Model):
    __tablename__ = 'web'
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), nullable=False)
    title = db.Column(db.String(20), nullable=False)
    word = db.Column(db.Text)