Пример #1
0
class Video(db.Model):
    __tablename__ = 'video'
    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)  # 播放量
    commentnum = db.Column(db.BigInteger)  # 评论量
    col_num = db.Column(db.Integer, default=0)  #收藏量
    up_num = db.Column(db.Integer, default=0)
    tag_id = db.Column(db.Integer, db.ForeignKey('tag.id'))  # 所属标签
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))  # 所属用户
    comments = db.relationship('Comment', backref='video')  # 评论
    video_cols = db.relationship('Videocol', backref='video')  # 收藏
    video_ups = db.relationship('Videoup', backref='video')  #点赞
    release_time = db.Column(db.Date)  # 上映时间
    area = db.Column(db.String(255))  # 上映地区
    length = db.Column(db.String(100))  # 播放时长
    addtime = db.Column(db.DateTime, index=True,
                        default=datetime.now())  # 添加时间

    def __repr__(self):
        return "<Video %r>" % self.title
Пример #2
0
class UserModel(db.Model, BaseModel):
    uid = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(32), nullable=False, unique=True)
    password = db.Column(db.String(128), nullable=False)
    portrait = db.Column(db.String(100))  #头像
    gender = db.Column(db.Integer, default=0)  #性别 0表示女 1表示男
    usertype = db.Column(db.Integer, default=0)  #用户类型 0普通用户 1版主 2表示管理员用户
    isactive = db.Column(db.Integer, default=0)  #用户是否可以登录 0表示激活可以登录 1表示不可以登录
    email = db.Column(db.String(200))
    autologin = db.Column(db.Integer, default=0)  #0表示不自动登录
    regtime = db.Column(db.DateTime, default=datetime.now)
    score = db.Column(db.Integer, default=50)  #积分

    # 和用户详细信息一对一关系
    detail = db.relationship('UserDetail', backref='user', uselist=False)

    #和帖子一对多
    posts = db.relationship('Posts', backref='user', lazy='dynamic')

    #和订单一对多
    orders = db.relationship('Orders', backref='user', lazy='dynamic')

    __tablename__ = 'bbs_user'

    def __str__(self):
        return self.username
Пример #3
0
class Room(BaseModel):

    name = db.Column(db.String(64), default='匿名聊天室')
    url = db.Column(db.String(255))

    host_id = db.Column(db.Integer, nullable=True)
    users = db.relationship('User', secondary='u_r', backref='rooms')

    messages = db.relationship('Message', backref='m_room', cascade='all')

    __tablename__ = 'room'
Пример #4
0
class Category(BaseModel, db.Model):

    __tablename__ = "info_category"

    id = db.Column(db.Integer, primary_key=True)  # 分类编号
    name = db.Column(db.String(64), nullable=False)  # 分类名
    news_list = db.relationship('News', backref='category', lazy='dynamic')
Пример #5
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    nickname = db.Column(db.String(64), index=True, unique=True)
    email = db.Column(db.String(120), index=True, unique=True)
    posts = db.relationship('Post', backref='author', lazy='dynamic')

    @property
    def is_authenticated(self):  # 被认证的
        return True

    @property
    def is_active(self):
        return True

    @property
    def is_anonymous(self):  # 是否匿名
        return False

    def get_id(self):
        # try:
        #     return unicode(self.id)  # python2
        # except NameError:
        # get_id 方法应该返回一个用户唯一的标识符,以 unicode 格式。我们使用数据库生成的唯一的 id。需要注意地是在 Python 2 和 3 之间由于 unicode 处理的方式的不同我们提供了相应的方式。
        return str(self.id)  # python3

    def __repr__(self):
        return '<User %r>' % (self.nickname)
Пример #6
0
class User(ModelBase, db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    u_name = db.Column(db.String(16), unique=True)
    u_age = db.Column(db.Integer)
    a_id = db.Column(db.Integer, db.ForeignKey('address.id'))
    address = db.relationship('Address',
                              backref=db.backref('user', lazy='dynamic'))
Пример #7
0
class PaiDang(BaseModel):
    p_movie = db.Column(db.Integer, db.ForeignKey(Movie.id))
    p_hall = db.Column(db.Integer, db.ForeignKey(Hall.id))
    p_time_start = db.Column(db.DateTime)
    p_time_end = db.Column(db.DateTime)
    p_price = db.Column(db.Float, default=1)
    seatorders = db.relationship('SeatOrder', backref="paidang", lazy=True)
Пример #8
0
class User(ModelBase, db.Model):
    __tablename = 'user'
    id = db.Column(db.Integer, primary_key=True)
    u_name = db.Column(db.String(16), unique=True)
    u_age = db.Column(db.Integer)
    u_sex = db.Column(db.Boolean)
    #  一对多
    books = db.relationship('book')
Пример #9
0
class Flight(BaseModel):
    __tablename__ = 'cinema_flight'
    f_movie_id = db.Column(db.Integer, db.ForeignKey(Movie.id))
    f_hall_id = db.Column(db.Integer, db.ForeignKey(Hall.id))
    f_time = db.Column(db.DateTime)
    f_price = db.Column(db.Float, default=40.0)

    movieorder = db.relationship('MovieOrder', backref='Flight', lazy=True)
Пример #10
0
class Admin(db.Model):
    __tablename__ = "admin"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(30), unique=True)  # 管理员账号
    password = db.Column(db.String(128))  # 管理员密码
    is_super = db.Column(db.SmallInteger)  # 是否是超级管理员 0为超级管理员
    role_id = db.Column(db.Integer, db.ForeignKey('role.id'))  # 所属角色
    addtime = db.Column(db.DateTime, index=True, default=datetime.now())
    adminlogs = db.relationship("Adminlog", backref='admin')
    Oplogs = db.relationship("Oplog", backref='admin')

    def __repr__(self):
        return "<Admin %r>" % self.name

    def check_pwd(self, pwd):
        from werkzeug.security import check_password_hash
        return check_password_hash(self.password, pwd)
Пример #11
0
class Role(db.Model):
    __tablename__ = "first-roles"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(50), unique=True)
    users = db.relationship('User', backref='role')

    def __repr__(self):
        return f"<Role {self.name}>"
Пример #12
0
class User(db.Model):
    u_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    u_name = db.Column(db.String(128), unique=True)
    u_password = db.Column(db.String(256), unique=True)
    u_nikename = db.Column(db.String(128))
    u_sex = db.Column(db.String(32), default='男')
    phone = db.Column(db.String(32))
    funs = db.Column(db.Integer)
    focus = db.Column(db.Integer)
    dynamics = db.Column(db.Integer)
    u_hot = db.Column(db.Integer)
    u_walk = db.Column(db.String(32))
    u_icon = db.Column(db.String(128), default=None)
    u_com = db.relationship('Community', backref='user')
    u_col = db.relationship('Collection', backref='user')
    u_comment = db.relationship('Comment', backref='user')
    u_order = db.relationship('Order', backref='user')
    u_cou = db.relationship('Course', backref='user')
Пример #13
0
class Cinema(BaseModel):

    c_name = db.Column(db.String(32), unique=True)
    c_address = db.Column(db.String(128))
    c_phone = db.Column(db.String(32))
    c_city = db.Column(db.String(32))
    c_user = db.Column(db.Integer, db.ForeignKey(CinemaUser.id))
    is_active = db.Column(db.Boolean, default=False)
    halls = db.relationship('Hall', backref="cinema", lazy=True)
class HallMovie(BaseModel):

    h_movie_id = db.Column(db.Integer, db.ForeignKey(Movie.id))

    h_hall_id = db.Column(db.Integer, db.ForeignKey(Hall.id))

    h_time = db.Column(db.DateTime)

    h_orders = db.relationship('MovieOrder', backref='HallMovie', lazy=True)
Пример #15
0
class Detail(db.Model):
    __tablename__ = 'detail'

    id = db.Column(db.Integer, primary_key=True)
    phone = db.Column(db.String(11))
    email = db.Column(db.String(200))
    uid = db.Column(db.ForeignKey('user.uid', ondelete='CASCADE'), unique=True)

    user = db.relationship('User', primaryjoin='Detail.uid == User.uid', backref='details')
Пример #16
0
class Reply(db.Model):
    __tablename__ = 'reply'

    rid = db.Column(db.Integer, primary_key=True)
    content = db.Column(db.String(3000))
    uid = db.Column(db.ForeignKey('user.uid', ondelete='CASCADE'), index=True)
    create_time = db.Column(db.DateTime)

    user = db.relationship('User', primaryjoin='Reply.uid == User.uid', backref='replies')
Пример #17
0
class User(BaseModel, db.Model):
    __tablename__ = 'ihome_user'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    phone = db.Column(db.String(11), unique=True)
    pwd_hash = db.Column(db.String(200))
    name = db.Column(db.String(30), unique=True)
    avatar = db.Column(db.String(100))  # 头像
    id_name = db.Column(db.String(30))  # 实名认证的姓名
    id_card = db.Column(db.String(18), unique=True)  # 实名认证的身份证号码

    houses = db.relationship('House', backref='user')
    orders = db.relationship('Order', backref='user')

    def save(self):
        db.session.add(self)
        db.session.commit()

    @property
    def password(self):
        return ''

    # 写
    @password.setter
    def password(self, pwd):
        self.pwd_hash = generate_password_hash(pwd)

    # 对比
    def check_pwd(self, pwd):
        return check_password_hash(self.pwd_hash, pwd)

    def to_auth_dict(self):
        return {
            'id_name': self.id_name,
            'id_card': self.id_card
        }

    def to_basic_dict(self):
        return {
            'id': self.id,
            'avatar': self.avatar if self.avatar else '',
            'name': self.name,
            'phone': self.phone
        }
Пример #18
0
class Tag(db.Model):
    __tablename__ = 'tag'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), unique=True)  # 标题
    addtime = db.Column(db.DateTime, index=True,
                        default=datetime.now())  # 添加时间
    videos = db.relationship('Video', backref='tag')

    def __repr__(self):
        return "<Tag %r>" % self.name
Пример #19
0
class Role(db.Model):
    __tablename__ = "role"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), unique=True)  # 名称
    auths = db.Column(db.String(600))
    addtime = db.Column(db.DateTime, index=True, default=datetime.now())
    admins = db.relationship("Admin", backref='role')

    def __repr__(self):
        return "<Role %r>" % self.name
Пример #20
0
class Tag(db.Model):
    __tablename__ = 'tag'

    tid = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(30), nullable=False)
    aid = db.Column(db.ForeignKey('article.aid'), index=True)

    article = db.relationship('Article',
                              primaryjoin='Tag.aid == Article.aid',
                              backref='tags')
Пример #21
0
class CartModel(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)

    c_num = db.Column(db.Integer)
    is_choosed = db.Column(db.Boolean, default=True)
    ordermodel = db.relationship('OrderModel',
                                 secondary='registrations',
                                 backref=db.backref('orders'),
                                 lazy='dynamic')
    __name__ = "App_cartmodel"
Пример #22
0
class ItemType(BaseModel):
    """项目类别模块"""
    __tablename__ = 'tbl_itemtype'
    name = db.Column(db.String(100), unique=True)
    parent = db.Column(db.Integer,
                       db.ForeignKey('tbl_itemtype.id'))  # 父项目类别,自关联
    itemplans = db.relationship("ItemPlan", backref="itemtype")  # 项目类别下的所有项目计划

    def __str__(self):
        return self.name
Пример #23
0
class Mark(db.Model):
    __tablename__ = 'mark'

    mid = db.Column(db.Integer, primary_key=True)
    content = db.Column(db.String(1000))
    creat_time = db.Column(db.DateTime, server_default=db.FetchedValue())
    uid = db.Column(db.ForeignKey('user.uid'), index=True)

    user = db.relationship('User',
                           primaryjoin='Mark.uid == User.uid',
                           backref='marks')
Пример #24
0
class SysUser(db.Model):
    __tablename__ = 'sys_user'
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(128), nullable=False)
    phone = db.Column(db.String(20))
    password = db.Column(db.String(256), nullable=False)
    roles = db.relationship('Role', backref='user')
    avatar = db.Column(
        db.String(256),
        default=
        'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif')
    name = db.Column(db.String(128), default='')
Пример #25
0
class Item(db.Model):
    __tablename__ = 'item'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(64), nullable=False)
    total = db.Column(db.Integer, nullable=False)
    price = db.Column(db.String(32), nullable=False)
    img = db.Column(db.String(64), default='img/default_item.png')
    detail_info = db.Column(db.Text, default='None info...')
    view_num = db.Column(db.Integer, default=0)
    requests = db.relationship('Request', backref='requests')
    create_time = db.Column(db.String(32), nullable=False,
                            default=str(datetime.now())[:str(datetime.now()).rfind('.'):])
Пример #26
0
class Movie(BaseModel):
    m_name = db.Column(db.String(128))
    m_name_en = db.Column(db.String(256))
    m_director = db.Column(db.String(64))
    m_leading_role = db.Column(db.String(256))
    m_duration = db.Column(db.Integer, default=90)
    m_country = db.Column(db.String(64))
    m_type = db.Column(db.String(64))
    m_screen_model = db.Column(db.String(32))
    m_open_day = db.Column(db.DateTime)
    m_introduce = db.Column(db.String(256))
    m_paidangs = db.relationship('PaiDang', backref="movie")
Пример #27
0
class Book(db.Model):
    # 给表重新定义一个名称,默认名称是类名的小写,比如该类默认的表名是book。
    __tablename__ = "book"
    bookID = db.Column(db.String(7),
                       primary_key=True,
                       unique=True,
                       nullable=False)
    bookName = db.Column(db.String(20))
    bookAuthor = db.Column(db.String(20))
    bookStorage = db.Column(db.Integer)
    bookInfo = db.Column(db.String(1000))
    bookShelf = db.Column(db.Integer)
    appointment = db.relationship('Appointment', backref='book')
Пример #28
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))
    email = db.Column(db.String(128), unique=True)
    phone = db.Column(db.String(16), unique=True)
    mood = db.Column(db.Text)  # 想说的话,签名
    icon = db.Column(db.String(255), unique=True)  # 头像
    addtime = db.Column(db.DateTime, index=True, default=datetime.now())
    uuid = db.Column(db.String(64))
    userlogs = db.relationship('Userlog', backref='user')
    videos = db.relationship('Video', backref='user')
    comments = db.relationship('Comment', backref='user')
    video_cols = db.relationship('Videocol', backref='user')

    def __repr__(self):
        return "<User %r>" % self.name

    def check_pwd(self, pwd):
        from werkzeug.security import check_password_hash
        return check_password_hash(self.password, pwd)
Пример #29
0
class Role(db.Model):
    r_id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    r_name = db.Column(db.String(10))
    users = db.relationship('User', backref='role')

    __tablename__ = 'role'

    def __init__(self, r_name):
        self.r_name = r_name

    def save(self):
        db.session.add(self)
        db.session.commit()
Пример #30
0
class Area(BaseModel, db.Model):
    """城区"""

    __tablename__ = "ihome_area"

    id = db.Column(db.Integer, primary_key=True)  # 区域编号
    name = db.Column(db.String(32), nullable=False)  # 区域名字
    houses = db.relationship("House", backref="area")  # 区域的房屋

    def to_dict(self):
        return {
            'id': self.id,
            'name': self.name
        }