mirror of https://github.com/doccano/doccano.git
Hironsan
2 years ago
4 changed files with 147 additions and 0 deletions
Split View
Diff Options
-
19backend/label_types/migrations/0004_rename_relationtype_relationtypeold.py
-
94backend/label_types/migrations/0005_relationtype_and_more.py
-
28backend/label_types/migrations/0006_auto_20220222_0512.py
-
6backend/label_types/models.py
@ -0,0 +1,19 @@ |
|||
# Generated by Django 4.0.2 on 2022-02-22 05:05 |
|||
|
|||
from django.db import migrations |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
("projects", "0003_alter_project_polymorphic_ctype"), |
|||
("labels", "0005_alter_relation_project"), |
|||
("label_types", "0003_auto_20220204_0201"), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.RenameModel( |
|||
old_name="RelationType", |
|||
new_name="RelationTypeOld", |
|||
), |
|||
] |
@ -0,0 +1,94 @@ |
|||
# Generated by Django 4.0.2 on 2022-02-22 05:11 |
|||
|
|||
from django.db import migrations, models |
|||
import django.db.models.deletion |
|||
import label_types.models |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
("projects", "0003_alter_project_polymorphic_ctype"), |
|||
("label_types", "0004_rename_relationtype_relationtypeold"), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.CreateModel( |
|||
name="RelationType", |
|||
fields=[ |
|||
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), |
|||
("text", models.CharField(db_index=True, max_length=100)), |
|||
( |
|||
"prefix_key", |
|||
models.CharField( |
|||
blank=True, |
|||
choices=[("ctrl", "ctrl"), ("shift", "shift"), ("ctrl shift", "ctrl shift")], |
|||
max_length=10, |
|||
null=True, |
|||
), |
|||
), |
|||
( |
|||
"suffix_key", |
|||
models.CharField( |
|||
blank=True, |
|||
choices=[ |
|||
("0", "0"), |
|||
("1", "1"), |
|||
("2", "2"), |
|||
("3", "3"), |
|||
("4", "4"), |
|||
("5", "5"), |
|||
("6", "6"), |
|||
("7", "7"), |
|||
("8", "8"), |
|||
("9", "9"), |
|||
("a", "a"), |
|||
("b", "b"), |
|||
("c", "c"), |
|||
("d", "d"), |
|||
("e", "e"), |
|||
("f", "f"), |
|||
("g", "g"), |
|||
("h", "h"), |
|||
("i", "i"), |
|||
("j", "j"), |
|||
("k", "k"), |
|||
("l", "l"), |
|||
("m", "m"), |
|||
("n", "n"), |
|||
("o", "o"), |
|||
("p", "p"), |
|||
("q", "q"), |
|||
("r", "r"), |
|||
("s", "s"), |
|||
("t", "t"), |
|||
("u", "u"), |
|||
("v", "v"), |
|||
("w", "w"), |
|||
("x", "x"), |
|||
("y", "y"), |
|||
("z", "z"), |
|||
], |
|||
max_length=1, |
|||
null=True, |
|||
), |
|||
), |
|||
( |
|||
"background_color", |
|||
models.CharField(default=label_types.models.generate_random_hex_color, max_length=7), |
|||
), |
|||
("text_color", models.CharField(default="#ffffff", max_length=7)), |
|||
("created_at", models.DateTimeField(auto_now_add=True, db_index=True)), |
|||
("updated_at", models.DateTimeField(auto_now=True)), |
|||
("project", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="projects.project")), |
|||
], |
|||
options={ |
|||
"ordering": ["created_at"], |
|||
"abstract": False, |
|||
}, |
|||
), |
|||
migrations.AddConstraint( |
|||
model_name="relationtype", |
|||
constraint=models.UniqueConstraint(fields=("project", "text"), name="label_types_relationtype_is_unique"), |
|||
), |
|||
] |
@ -0,0 +1,28 @@ |
|||
# Generated by Django 4.0.2 on 2022-02-22 05:12 |
|||
|
|||
from django.db import migrations |
|||
|
|||
|
|||
def copy_relation_type(apps, schema_editor): |
|||
RelationTypeOld = apps.get_model("label_types", "RelationTypeOld") |
|||
RelationType = apps.get_model("label_types", "RelationType") |
|||
for relation_type in RelationTypeOld.objects.all(): |
|||
RelationType( |
|||
background_color=relation_type.color, text=relation_type.name, project=relation_type.project |
|||
).save() |
|||
|
|||
|
|||
def delete_new_relation_type(apps, schema_editor): |
|||
RelationType = apps.get_model("label_types", "RelationType") |
|||
RelationType.objects.all().delete() |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
("label_types", "0005_relationtype_and_more"), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.RunPython(code=copy_relation_type, reverse_code=delete_new_relation_type), |
|||
] |
Write
Preview
Loading…
Cancel
Save