Browse Source

生成数据库SchoolDept模型和迁移文件

DYaiu 4 years ago
parent
commit
46b9fdc076

+ 2 - 1
my_project/settings.py

@@ -38,7 +38,8 @@ INSTALLED_APPS = [
     'rest_framework',
     'django_filters',
     'workreport',
-    'mptt'
+    'mptt',
+    'workTtree'
 ]
 
 MIDDLEWARE = [

+ 36 - 0
workTtree/migrations/0001_initial.py

@@ -0,0 +1,36 @@
+# Generated by Django 3.0.8 on 2020-07-21 08:51
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    initial = True
+
+    dependencies = [
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='SchoolDept',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('name', models.CharField(max_length=20)),
+                ('remark', models.TextField(null=True)),
+                ('create_at', models.DateField(auto_now_add=True, verbose_name='创建人')),
+                ('update_at', models.DateField(auto_now=True, null=True, verbose_name='最后修改时间')),
+                ('lft', models.PositiveIntegerField(editable=False)),
+                ('rght', models.PositiveIntegerField(editable=False)),
+                ('tree_id', models.PositiveIntegerField(db_index=True, editable=False)),
+                ('level', models.PositiveIntegerField(editable=False)),
+                ('create_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='children', to='workTtree.SchoolDept')),
+                ('update_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='workTtree.SchoolDept', verbose_name='最后修改人')),
+            ],
+            options={
+                'verbose_name': '学校部门树形结构',
+                'verbose_name_plural': '学校部门树形结构列表',
+                'db_table': 'school_dept_tree',
+            },
+        ),
+    ]

+ 0 - 0
workTtree/migrations/__init__.py


+ 23 - 0
workTtree/models.py

@@ -0,0 +1,23 @@
+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)
+    # 创建时间,只有在创建的时候会自动填充当前时间
+    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)
+    # 更新时间
+    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='最后修改人')
+
+    class Meta:
+        db_table = 'school_dept_tree'
+        verbose_name = '学校部门树形结构'
+        verbose_name_plural = '学校部门树形结构列表'