models.py 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. from django.contrib.auth.models import User
  2. from django.db import models
  3. from mptt.fields import TreeForeignKey
  4. from mptt.models import MPTTModel
  5. # 部门表
  6. class Dept(MPTTModel):
  7. name = models.CharField(max_length=50)
  8. parent = TreeForeignKey('self', on_delete=models.CASCADE, null=True, blank=True, related_name='children')
  9. class Meta:
  10. verbose_name = '部门表'
  11. # 岗位表
  12. class Jobs(models.Model):
  13. name = models.CharField(max_length=50)
  14. class Meta:
  15. verbose_name = '岗位表'
  16. # 部门表 2 岗位表 关联表
  17. class Dept2Jobs(models.Model):
  18. # 得到指定model的外键,会拿主键当外键,比如id,然后会在数据库生成字段后+ '_id'
  19. dept = models.ForeignKey('Dept', on_delete=models.CASCADE, blank=True, null=True)
  20. job = models.ForeignKey('Jobs', on_delete=models.CASCADE, blank=True, null=True)
  21. user = models.ForeignKey(User, on_delete=models.CASCADE, blank=True, null=True)
  22. class Meta:
  23. verbose_name = '部门岗位关联表'