The Seven Year Itch.

MENU

Flask 项目系列 -- 基于Flask打造招聘网站(2017-12-07更新)

November 5, 2017 • Read: 726 • 数据库,Linux,Python

  1. 项目结构搭建
  2. 项目数据库的设计
  3. 我有罪,其实这个项目一直在写,只是没时间编写文章了。马上就有时间了。现在项目进展如下:
    现在已经可以部署了,就是前端还有点丑。

前端

写好脚本

简要描述:

  • 首先使用pip 安装flask
    pip install -i https://pypi.douban.com/simple
  • 创建目录

jobpuls
--jobplus
|---__init__.py
|---app.py
|---config.py
|---forms.py
|---models.py
|---decorator.py
|---handlers
||---front.py
||---admin.py
|---static
||---js
||---css
|---templates
--manage.py
结构搭建
列表数
下载flask-migarte
pip install flask-migarte
models设计完成之后运行
export FLASK_APP=manage.py
export FLASK_DEBUG=1
flask db init
flask migarte -m "init database"
flask upgrade

models设计后面加上。

  1. 数据库

更新models.py

class Base(db.Model):
    __abstract__ = True
    created_at = db.Column(db.DateTime, default=datetime.utcnow)
    updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
    deleted = db.Column(db.Integer, default=0)  # 逻辑删除:0表示显示,1表示删除


user_job = db.Table(
    'user_job',
    db.Column('user_id', db.Integer, db.ForeignKey('user.id', ondelete='CASCADE')),
    db.Column('job_id', db.Integer, db.ForeignKey('jobs.id', ondelete='CASCADE'))
)


class User(Base, UserMixin):
    """
    用户表
    """
    __tablename__ = 'user'

    ROLE_USER = 10
    ROLE_STAFF = 20
    ROLE_ADMIN = 30

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(40), unique=True)
    email = db.Column(db.String(40), unique=True)
    phone = db.Column(db.Integer)
    _password = db.Column('password', db.String(256), nullable=False)
    role = db.Column(db.SmallInteger, default=ROLE_USER)

    def __repr__(self):
        return '<Admin:{}>'.format(self.username)

    @property
    def password(self):
        return self._password

    @password.setter
    def password(self, orig_password):
        self._password = generate_password_hash(orig_password)

    def check_password(self, password):
        return check_password_hash(self._password, password)

    @property
    def is_admin(self):
        return self.role == self.ROLE_ADMIN

    @property
    def is_staf(self):
        return self.role == self.ROLE_STAFF


class Resume(Base):
    """
    用户简历表
    """
    __tabalename__ = 'resume'

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relationship('User', uselist=False)
    job_experiences = db.relationship('JobExperience')
    edu_experiences = db.relationship('EduExperience')
    project_experiences = db.relationship('ProjectExperice')

    def profile(self):
        pass


class Experience(Base):
    __abstract__ = True

    id = db.Column(db.Integer, primary_key=True)
    begin_at = db.Column(db.DateTime)
    end_at = db.Column(db.DateTime)
    # 在职期间,做了什么,解决了什么问题,做出了什么贡献
    # 在校期间做过什么,取得过什么荣誉
    # 项目期间,做了什么,解决了什么问题,做出了什么贡献
    description = db.Column(db.String(1024))


class JobExperience(Experience):
    __tablename__ = 'job_experience'

    company = db.Column(db.String(32), nullable=False)
    city = db.Column(db.String(32), nullable=False)
    resume_id = db.Column(db.Integer, db.ForeignKey('resume.id'))
    resume = db.relationship('Resume', uselist=False)


class ProjectExperice(Experience):
    __tablename__ = 'project_experience'

    name = db.Column(db.String(32), nullable=False)
    # 在项目中扮演的角色
    role = db.Column(db.String(32))
    # 多个技术用逗号隔开
    technologys = db.Column(db.String(64))
    resume_id = db.Column(db.Integer, db.ForeignKey('resume.id'))
    resume = db.relationship('Resume', uselist=False)


class EduExperience(Experience):
    __tablename__ = 'edu_experience'

    school = db.Column(db.String(32), nullable=False)
    # 所学专业
    specialty = db.Column(db.String(32), nullable=False)
    degree = db.Column(db.String(16))
    resume_id = db.Column(db.Integer, db.ForeignKey('resume.id'))
    resume = db.relationship('Resume', uselist=False)


class Jobs(Base):
    __tablename__ = 'jobs'

    id = db.Column(db.Integer, primary_key=True)
    # 职位名称
    name = db.Column(db.String(24))
    salary_low = db.Column(db.Integer, nullable=False)
    salary_high = db.Column(db.Integer, nullable=False)
    location = db.Column(db.String(24))
    # 职位标签,多个标签用逗号隔开,最多10个
    tags = db.Column(db.String(128))
    experience_requirement = db.Column(db.String(32))
    degree_requirement = db.Column(db.String(32))
    is_fulltime = db.Column(db.Boolean, default=True)
    # 是否在招聘
    is_open = db.Column(db.Boolean, default=True)
    company_id = db.Column(db.Integer, db.ForeignKey('company.id', ondelete='CASCADE'))
    company = db.relationship('Company', uselist=False)
    views_count = db.Column(db.Integer, default=0)

    def __repr__(self):
        return '<Job {}>'.format(self.name)


class Company(Base):
    __tablename__ = 'company'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), nullable=False, index=True, unique=True)
    slug = db.Column(db.String(24), nullable=False, index=True, unique=True)
    logo = db.Column(db.String(64), nullable=False)
    site = db.Column(db.String(64), nullable=False)
    contact = db.Column(db.String(24), nullable=False)
    email = db.Column(db.String(24), nullable=False)
    location = db.Column(db.String(24), nullable=False)
    # 一句话描述
    description = db.Column(db.String(100))
    # 关于我们,公司详情描述
    about = db.Column(db.String(1024))
    # 公司标签,多个标签用逗号隔开,最多10个
    tags = db.Column(db.String(128))
    # 公司技术栈,多个技术用逗号隔开,最多10个
    stack = db.Column(db.String(128))
    # 团队介绍
    team_introduction = db.Column(db.String(256))
    # 公司福利,多个福利用分号隔开,最多 10 个
    welfares = db.Column(db.String(256))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id', ondelete='SET NULL'))
    user = db.relationship('User', uselist=False, backref=db.backref('company', uselist=False))


class Dilivery(Base):
    __tablename__ = 'delivery'

    # 等待企业审核
    STATUS_WAITING = 1
    # 被拒绝
    STATUS_REJECT = 2
    # 被接收,等待通知面试
    STATUS_ACCEPT = 3

    id = db.Column(db.Integer, primary_key=True)
    job_id = db.Column(db.Integer, db.ForeignKey('jobs.id', ondelete='SET NULL'))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id', ondelete='SET NULL'))
    status = db.Column(db.SmallInteger, default=STATUS_WAITING)
    # 企业回应
    response = db.Column(db.String(256))

后面再改表的显示吧

用户表

12345
Tags: None
Archives QR Code
QR Code for this page
Tipping QR Code
Leave a Comment

已有 2 条评论
  1. 项目dalao。@(滑稽)@(大拇指)

    1. @后宫学长@(惊哭)@(惊哭)