Пример #1
0
#! coding: utf8

from admin import db
from flask_login import UserMixin


user_role = db.Table(
        'user_role',
        db.Column('user_id', db.Integer, db.ForeignKey('user.id'), primary_key=True),
        db.Column('role_id', db.Integer, db.ForeignKey('role.id'), primary_key=True),
    )


class User(db.Model, UserMixin):
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(32), unique=True, nullable=False)
    email = db.Column(db.String(128), unique=True, nullable=False)
    password = db.Column(db.String(128), nullable=False)
    is_admin = db.Column(db.Integer, default=0, nullable=False)  # 是否管理员 0 不是 1 是
    status = db.Column(db.Integer, default=1, nullable=False)  # 是否有效 0 无效 1有效

    roles = db.relationship(
        "Role",
        secondary=user_role,
        lazy='subquery',
        backref=db.backref('users', lazy=True),
    )

    # 功能模块-用户关联部分
    # 定义一对多关系
Пример #2
0
    @phone_number.expression
    def phone_number(cls):
        return sql.operators.ColumnOperators.concat(cast(cls.dialling_code, db.String), cls.local_phone_number)

    def __str__(self):
        return "{}, {}".format(self.last_name, self.first_name)

    def __repr__(self):
        return "{}: {}".format(self.id, self.__str__())




#---<Create M2M table>---#
post_tags_table = db.Table('post_tags', db.Model.metadata,
                           db.Column('post_id', db.Integer, db.ForeignKey('post.id')),
                           db.Column('tag_id', db.Integer, db.ForeignKey('tag.id'))
                           )


class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(120))
    text = db.Column(db.Text, nullable=False)
    date = db.Column(db.Date)

    # some sqlalchemy_utils data types (see https://sqlalchemy-utils.readthedocs.io/)
    background_color = db.Column(ColorType)
    created_at = db.Column(ArrowType, default=arrow.utcnow())
    user_id = db.Column(UUIDType(binary=False), db.ForeignKey(User.id))

    user = db.relationship(User, foreign_keys=[user_id], backref='posts')
Пример #3
0
    @property
    def get_data(self):
        dictionary = self.__dict__
        try:
            del dictionary['_sa_instance_state']
            if dictionary['deadline'] != None:
                dictionary['deadline'] = str(dictionary['deadline'])
            dictionary['crawl_date'] = str(dictionary['crawl_date'])
            dictionary['skill_tag'] = dictionary['skill_tag'].split(',')
        except:
            pass
        return dictionary


skills_sector_table = db.Table(
    'skill_sector', db.Model.metadata,
    db.Column('job_skill_id', db.Integer, db.ForeignKey('jobskill.id')),
    db.Column('job_sector_id', db.Integer, db.ForeignKey('jobsector.id')))


class JobSkill(db.Model):
    __tablename__ = "jobskill"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(200))
    sector = db.relationship('JobSector', secondary=skills_sector_table)

    def __str__(self):
        return "{}".format(self.name)

    @property
    def get_data(self):
        dictionary = self.__dict__