Browse Source

Rename RelationNew to Relation

pull/1703/head
Hironsan 2 years ago
parent
commit
6281bcae26
4 changed files with 31 additions and 9 deletions
  1. 21
      backend/labels/migrations/0010_rename_relationnew_relation.py
  2. 2
      backend/labels/models.py
  3. 11
      backend/labels/serializers.py
  4. 6
      backend/labels/views.py

21
backend/labels/migrations/0010_rename_relationnew_relation.py

@ -0,0 +1,21 @@
# Generated by Django 4.0.2 on 2022-02-22 07:04
from django.conf import settings
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("label_types", "0007_delete_relationtypeold"),
("examples", "0002_alter_example_project"),
("labels", "0009_delete_relationold"),
]
operations = [
migrations.RenameModel(
old_name="RelationNew",
new_name="Relation",
),
]

2
backend/labels/models.py

@ -90,7 +90,7 @@ class TextLabel(Label):
unique_together = ("example", "user", "text")
class RelationNew(Label):
class Relation(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)

11
backend/labels/serializers.py

@ -1,8 +1,8 @@
from rest_framework import serializers
from .models import Category, RelationNew, Span, TextLabel
from .models import Category, Relation, Span, TextLabel
from examples.models import Example
from label_types.models import CategoryType, SpanType
from label_types.models import CategoryType, RelationType, SpanType
class CategorySerializer(serializers.ModelSerializer):
@ -61,9 +61,10 @@ class TextLabelSerializer(serializers.ModelSerializer):
class RelationSerializer(serializers.ModelSerializer):
def validate(self, attrs):
return super().validate(attrs)
example = serializers.PrimaryKeyRelatedField(queryset=Example.objects.all())
type = serializers.PrimaryKeyRelatedField(queryset=RelationType.objects.all())
class Meta:
model = RelationNew
model = Relation
fields = ("id", "prob", "user", "example", "created_at", "updated_at", "from_id", "to_id", "type")
read_only_fields = ("user",)

6
backend/labels/views.py

@ -14,7 +14,7 @@ from .serializers import (
SpanSerializer,
TextLabelSerializer,
)
from labels.models import Category, Label, RelationNew, Span, TextLabel
from labels.models import Category, Label, Relation, Span, TextLabel
from projects.models import Project
from projects.permissions import IsProjectMember
@ -118,12 +118,12 @@ class RelationList(generics.ListCreateAPIView):
def delete(self, request, *args, **kwargs):
delete_ids = request.data["ids"]
RelationNew.objects.filter(pk__in=delete_ids).delete()
Relation.objects.filter(pk__in=delete_ids).delete()
return Response(status=status.HTTP_204_NO_CONTENT)
class RelationDetail(generics.RetrieveUpdateDestroyAPIView):
queryset = RelationNew.objects.all()
queryset = Relation.objects.all()
serializer_class = RelationSerializer
lookup_url_kwarg = "annotation_id"
permission_classes = [IsAuthenticated & IsProjectMember]
Loading…
Cancel
Save