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