职位管理系统 - 建模
- 职位名称
- 类别
- 工作地点
- 职位职责
- 职位要求
- 发布人
- 发布日期
- 修改日期
安装django
pip install django==5.0
查看django版本
python -m django --version
创建项目
django-admin startproject recruitment
启动服务
python manage.py runserver 0.0.0.0:8000
创建应用
python .\manage.py startapp jobs
jobs表示关于职位管理的应用
生成迁移文件
python .\manage.py makemigrations
迁移数据
python .\manage.py migrate
创建后台管理员账号
python .\manage.py createsuperuser
创建模型
from datetime import datetime
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
JobTypes = [
(0, "技术类"),
(1, "产品类"),
(2, "运营类"),
(3, "设计类"),
]
Cities = [
(0, "北京"),
(0, "上海"),
(0, "深圳"),
(0, "西安"),
]
class Job(models.Model):
job_type = models.SmallIntegerField(blank=False, choices=JobTypes, verbose_name="职位类别")
job_name = models.CharField(max_length=250, blank=False, verbose_name="职位名称")
job_city = models.SmallIntegerField(choices=Cities, blank=False, verbose_name="工作地点")
job_responsibility = models.TextField(max_length=1024, verbose_name="职位职责")
job_requirements = models.TextField(max_length=1024, blank=False, verbose_name="职位要求")
creator = models.ForeignKey(User, verbose_name="创建人", null=True, on_delete=models.SET_NULL)
created_date = models.DateTimeField(verbose_name="创建时间", default=datetime.now)
modified_date = models.DateTimeField(verbose_name="修改时间", default=datetime.now)
注册模型
from django.contrib import admin
from jobs.models import Job
# Register your models here.
admin.site.register(Job)
注册应用
在settings.py INSTALLED_APPS
下注册应用
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'jobs'
]
迁移模型
python .\manage.py makemigrations
python .\manage.py migrate
标签:name,models,创建,py,django,python,应用,Django,verbose
From: https://www.cnblogs.com/jiucheng18/p/18181121