models.py 1.1 KB

12345678910111213141516171819202122232425
  1. from mptt.models import MPTTModel, TreeForeignKey
  2. from django.db import models
  3. # 实体表,需要migrate
  4. class SchoolDept(MPTTModel):
  5. # 标题字段,最长20
  6. name = models.CharField(max_length=20)
  7. # 备注字段
  8. remark = models.TextField(null=True)
  9. # 父节点
  10. parent = TreeForeignKey('self', on_delete=models.CASCADE, null=True, blank=True, related_name='children_p')
  11. # 创建时间,只有在创建的时候会自动填充当前时间
  12. create_at = models.DateField(auto_now_add=True, verbose_name='创建人')
  13. # 创建人,外键类型
  14. create_by = models.ForeignKey("self", blank=True, null=True, related_name="children_c", on_delete=models.CASCADE)
  15. # 更新时间
  16. update_at = models.DateField(auto_now=True, null=True, verbose_name='最后修改时间')
  17. # 更新人,外键类型
  18. update_by = models.ForeignKey("self", blank=True, null=True, on_delete=models.CASCADE, verbose_name='最后修改人',related_name='children_u')
  19. class Meta:
  20. db_table = 'school_dept_tree'
  21. verbose_name = '学校部门树形结构'
  22. verbose_name_plural = '学校部门树形结构列表'