1234567891011121314151617181920212223242526272829303132 |
- from django.contrib.auth.models import User
- from django.db import models
- from mptt.fields import TreeForeignKey
- from mptt.models import MPTTModel
- # 部门表
- class Dept(MPTTModel):
- name = models.CharField(max_length=50)
- parent = TreeForeignKey('self', on_delete=models.CASCADE, null=True, blank=True, related_name='children')
- class Meta:
- verbose_name = '部门表'
- # 岗位表
- class Jobs(models.Model):
- name = models.CharField(max_length=50)
- class Meta:
- verbose_name = '岗位表'
- # 部门表 2 岗位表 关联表
- class Dept2Jobs(models.Model):
- # 得到指定model的外键,会拿主键当外键,比如id,然后会在数据库生成字段后+ '_id'
- dept = models.ForeignKey('Dept', on_delete=models.CASCADE, blank=True, null=True)
- job = models.ForeignKey('Jobs', on_delete=models.CASCADE, blank=True, null=True)
- user = models.ForeignKey(User, on_delete=models.CASCADE, blank=True, null=True)
- class Meta:
- verbose_name = '部门岗位关联表'
|