1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- from django.contrib.auth.models import User
- from mptt.fields import TreeForeignKey
- from mptt.models import MPTTModel
- from django.db import models
- # 岗位表
- class Job(models.Model):
- name = models.CharField(max_length=20)
- class Meta:
- # db_table = 'job'
- verbose_name = '岗位表'
- verbose_name_plural = '学校部门树形结构列表'
- # 部门表
- class Department(MPTTModel):
- name = models.CharField(max_length=20)
- # 本表的树状
- parent = TreeForeignKey('self', on_delete=models.CASCADE, null=True, blank=True)
- class Meta:
- # db_table = 'department'
- verbose_name = '部门表'
- verbose_name_plural = '部门列表'
- # 部门岗位中间表
- class Dept_job(models.Model):
- # 部门外键
- dept = models.ForeignKey('Department', on_delete=models.CASCADE)
- # 岗位外键
- job = models.ForeignKey('Job', on_delete=models.CASCADE)
- class Meta:
- db_table = 'dept_job'
- verbose_name = '部门岗位表'
- verbose_name_plural = '部门岗位关联表'
- unique_together = ('dept', 'job')
- # 部门岗位中间表加人员的中间表
- class Dept_job_user(models.Model):
- # 部门外键
- dept_job = models.ForeignKey('Dept_job', on_delete=models.CASCADE)
- # 人员外键
- user = models.ForeignKey(User, on_delete=models.CASCADE)
- class Meta:
- db_table = 'dept_job_user'
- verbose_name = '部门岗位关联人员表'
- verbose_name_plural = '部门岗位关联人员关联表'
- unique_together = ('dept_job', 'user')
|