导入其他APP的表:
from department_manage.models import Department
外键连接时写法:
如果连接本models中的表:to=“表名”,
连接其他app中models中的表:to=表名(不加引号)
department = models.ForeignKey(to=Department, verbose_name="部门", to_field="id", on_delete=models.CASCADE)
from django.db import models
from department_manage.models import Department
# Create your models here.
class User(models.Model):
"""
用户表结构
fields = ["ID", "user_name", "gender", "department", "post", "authority", "password"]
"""
gender_choices = ((1, "男"), (2, "女"))
post_choices = ((1, "总经理"), (2, "副总经理"), (3, "部门经理"), (4, "部门主任"), (5, "组长"), (6, "员工"))
authority_choices = ((1, "超级管理员权限"), (2, "部门管理员权限"), (3, "普通权限"))
user_name = models.CharField(verbose_name="用户名", max_length=6)
gender = models.SmallIntegerField(verbose_name="性别", choices=gender_choices)
password = models.CharField(verbose_name="密码", max_length=16)
department = models.ForeignKey(to=Department, verbose_name="部门", to_field="id", on_delete=models.CASCADE)
post = models.SmallIntegerField(verbose_name="职务", choices=post_choices)
authority = models.SmallIntegerField(verbose_name="权限", choices=authority_choices)