From f3b60ae493dcb4a5115078a36736d8fee6a54d20 Mon Sep 17 00:00:00 2001 From: "descansodj@hotmail.it" <#git#87865#> Date: Wed, 21 Apr 2021 17:08:10 +0200 Subject: [PATCH] #27642 models and migrations --- ...009_annotations_relations_20210421_1445.py | 34 +++++++++++++++++++ app/api/models.py | 19 +++++++++++ 2 files changed, 53 insertions(+) create mode 100644 app/api/migrations/0009_annotations_relations_20210421_1445.py diff --git a/app/api/migrations/0009_annotations_relations_20210421_1445.py b/app/api/migrations/0009_annotations_relations_20210421_1445.py new file mode 100644 index 00000000..7106b755 --- /dev/null +++ b/app/api/migrations/0009_annotations_relations_20210421_1445.py @@ -0,0 +1,34 @@ +# Generated by Django 3.1.6 on 2021-03-02 10:13 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0008_auto_20210302_1013'), + ] + + operations = [ + migrations.CreateModel( # id_autogen, annotation_id_1, annotation_id_2, type, author, timestamp + name='RelationTypes', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.TextField(max_length=50)), + ('color', models.TextField(max_length=20)), + ('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='relation_types', to='api.Project')) + ], + ), + migrations.CreateModel( # id_autogen, annotation_id_1, annotation_id_2, type, author, timestamp + name='AnnotationRelations', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('annotation_id_1', models.IntegerField()), + ('annotation_id_2', models.IntegerField()), + ('type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.RelationTypes')), + ('timestamp', models.DateTimeField(auto_now_add=True)) + ], + ) + ] diff --git a/app/api/models.py b/app/api/models.py index cb367151..9fdaa41c 100644 --- a/app/api/models.py +++ b/app/api/models.py @@ -265,6 +265,25 @@ class SequenceAnnotation(Annotation): unique_together = ('document', 'user', 'label', 'start_offset', 'end_offset') +class AnnotationRelations: + user = models.ForeignKey(User, on_delete=models.CASCADE) + timestamp = models.DateTimeField(auto_now_add=True) + annotation_id_1 = models.IntegerField() + annotation_id_2 = models.IntegerField() + type = models.CharField(max_length=50) + + class Meta: + unique_together = ('timestamp', 'user', 'annotation_id_1', 'annotation_id_2', 'type') + + +class RelationTypes: + color = models.TextField() + name = models.TextField() + + class Meta: + unique_together = ('color', 'name') + + class Seq2seqAnnotation(Annotation): # Override AnnotationManager for custom functionality objects = Seq2seqAnnotationManager()