Browse Source

Add type field to Label model and add schema and data migrations

pull/1619/head
Hironsan 2 years ago
parent
commit
441cded138
3 changed files with 63 additions and 0 deletions
  1. 18
      backend/api/migrations/0020_label_task_type.py
  2. 36
      backend/api/migrations/0021_auto_20211209_0644.py
  3. 9
      backend/api/models.py

18
backend/api/migrations/0020_label_task_type.py

@ -0,0 +1,18 @@
# Generated by Django 3.2.8 on 2021-12-09 06:38
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0019_auto_20211124_0506'),
]
operations = [
migrations.AddField(
model_name='label',
name='task_type',
field=models.CharField(choices=[('Category', 'Category'), ('Span', 'Span'), ('Relation', 'Relation')], default='Category', max_length=30),
),
]

36
backend/api/migrations/0021_auto_20211209_0644.py

@ -0,0 +1,36 @@
from django.db import migrations
def update_label_type(apps, schema_editor):
Label = apps.get_model('api', 'Label')
for label in Label.objects.all():
project_type = label.project.project_type
if project_type.endswith('Classification'):
label.task_type = 'Category'
else:
label.task_type = 'Span'
label.save()
# def move_relation_type_to_label(apps, schema_editor):
# Label = apps.get_model('api', 'Label')
# RelationTypes = apps.get_model('api', 'RelationTypes')
# for relation_type in RelationTypes.objects.all():
# Label.objects.create(
# text=relation_type.name,
# project=relation_type.project,
# background_color=relation_type.color,
# task_type='Relation'
# )
class Migration(migrations.Migration):
dependencies = [
('api', '0020_label_task_type'),
]
operations = [
migrations.RunPython(update_label_type),
# migrations.RunPython(move_relation_type_to_label),
]

9
backend/api/models.py

@ -126,6 +126,15 @@ class Label(models.Model):
)
background_color = models.CharField(max_length=7, default=generate_random_hex_color)
text_color = models.CharField(max_length=7, default='#ffffff')
task_type = models.CharField(
max_length=30,
choices=(
('Category', 'Category'),
('Span', 'Span'),
('Relation', 'Relation')
),
default='Category'
)
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
updated_at = models.DateTimeField(auto_now=True)

Loading…
Cancel
Save