models.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. from django.contrib.auth.models import User
  2. from mptt.fields import TreeForeignKey
  3. from mptt.models import MPTTModel
  4. from django.db import models
  5. # 岗位表
  6. class Job(models.Model):
  7. name = models.CharField(max_length=20)
  8. class Meta:
  9. # db_table = 'job'
  10. verbose_name = '岗位表'
  11. verbose_name_plural = '学校部门树形结构列表'
  12. # 部门表
  13. class Department(MPTTModel):
  14. name = models.CharField(max_length=20)
  15. # 本表的树状
  16. parent = TreeForeignKey('self', on_delete=models.CASCADE, null=True, blank=True)
  17. class Meta:
  18. # db_table = 'department'
  19. verbose_name = '部门表'
  20. verbose_name_plural = '部门列表'
  21. # 部门岗位中间表
  22. class Dept_job(models.Model):
  23. # 部门外键
  24. dept = models.ForeignKey('Department', on_delete=models.CASCADE)
  25. # 岗位外键
  26. job = models.ForeignKey('Job', on_delete=models.CASCADE)
  27. class Meta:
  28. db_table = 'dept_job'
  29. verbose_name = '部门岗位表'
  30. verbose_name_plural = '部门岗位关联表'
  31. unique_together = ('dept', 'job')
  32. # 部门岗位中间表加人员的中间表
  33. class Dept_job_user(models.Model):
  34. # 部门外键
  35. dept_job = models.ForeignKey('Dept_job', on_delete=models.CASCADE)
  36. # 人员外键
  37. user = models.ForeignKey(User, on_delete=models.CASCADE)
  38. class Meta:
  39. db_table = 'dept_job_user'
  40. verbose_name = '部门岗位关联人员表'
  41. verbose_name_plural = '部门岗位关联人员关联表'
  42. unique_together = ('dept_job', 'user')