From edc90608c7f7911f11f6e13e9f4d5c918057f57e Mon Sep 17 00:00:00 2001 From: Hironsan Date: Tue, 22 Feb 2022 14:58:04 +0900 Subject: [PATCH] Add new Relation model --- backend/labels/migrations/0007_relationnew.py | 37 +++++++++++++++++++ backend/labels/models.py | 17 ++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 backend/labels/migrations/0007_relationnew.py diff --git a/backend/labels/migrations/0007_relationnew.py b/backend/labels/migrations/0007_relationnew.py new file mode 100644 index 00000000..5df2bcea --- /dev/null +++ b/backend/labels/migrations/0007_relationnew.py @@ -0,0 +1,37 @@ +# Generated by Django 4.0.2 on 2022-02-22 06:15 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('label_types', '0006_auto_20220222_0512'), + ('examples', '0002_alter_example_project'), + ('labels', '0006_rename_relation_relationold'), + ] + + operations = [ + migrations.CreateModel( + name='RelationNew', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('prob', models.FloatField(default=0.0)), + ('manual', models.BooleanField(default=False)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ('direction', models.CharField(choices=[('left', 'left'), ('right', 'right'), ('undirected', 'undirected')], default='undirected', max_length=10)), + ('example', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='relations', to='examples.example')), + ('from_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='from_relations', to='labels.span')), + ('to_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='to_relations', to='labels.span')), + ('type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='label_types.relationtype')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/backend/labels/models.py b/backend/labels/models.py index a4cde33e..90a4e0b6 100644 --- a/backend/labels/models.py +++ b/backend/labels/models.py @@ -4,7 +4,7 @@ from django.db import models from .managers import CategoryManager, LabelManager, SpanManager, TextLabelManager from examples.models import Example -from label_types.models import CategoryType, RelationTypeOld, SpanType +from label_types.models import CategoryType, RelationType, RelationTypeOld, SpanType from projects.models import Project @@ -104,3 +104,18 @@ class RelationOld(models.Model): class Meta: unique_together = ("annotation_id_1", "annotation_id_2", "type", "project") + + +class RelationNew(Label): + from_id = models.ForeignKey(Span, on_delete=models.CASCADE, related_name="from_relations") + to_id = models.ForeignKey(Span, on_delete=models.CASCADE, related_name="to_relations") + type = models.ForeignKey(RelationType, on_delete=models.CASCADE) + example = models.ForeignKey(to=Example, on_delete=models.CASCADE, related_name="relations") + direction = models.CharField( + max_length=10, + choices=(("left", "left"), ("right", "right"), ("undirected", "undirected")), + default="undirected", + ) + + def __str__(self): + return self.__dict__.__str__()