Browse Source

修改数据库SchoolDept模型和迁移文件

DYaiu 4 years ago
parent
commit
2651b7edfc
2 changed files with 34 additions and 2 deletions
  1. 30 0
      workTtree/migrations/0002_auto_20200721_1734.py
  2. 4 2
      workTtree/models.py

+ 30 - 0
workTtree/migrations/0002_auto_20200721_1734.py

@@ -0,0 +1,30 @@
+# Generated by Django 3.0.8 on 2020-07-21 09:34
+
+from django.db import migrations, models
+import django.db.models.deletion
+import mptt.fields
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('workTtree', '0001_initial'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='schooldept',
+            name='parent',
+            field=mptt.fields.TreeForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='children_p', to='workTtree.SchoolDept'),
+        ),
+        migrations.AlterField(
+            model_name='schooldept',
+            name='create_by',
+            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='children_c', to='workTtree.SchoolDept'),
+        ),
+        migrations.AlterField(
+            model_name='schooldept',
+            name='update_by',
+            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='children_u', to='workTtree.SchoolDept', verbose_name='最后修改人'),
+        ),
+    ]

+ 4 - 2
workTtree/models.py

@@ -8,14 +8,16 @@ class SchoolDept(MPTTModel):
     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", on_delete=models.CASCADE)
+    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='最后修改人')
+    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'