Browse Source

Add new Relation model

pull/1703/head
Hironsan 2 years ago
parent
commit
edc90608c7
2 changed files with 53 additions and 1 deletions
  1. 37
      backend/labels/migrations/0007_relationnew.py
  2. 17
      backend/labels/models.py

37
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,
},
),
]

17
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__()
Loading…
Cancel
Save