From 375604ba2aeced42de553ffb8e0db1cf67c4889c Mon Sep 17 00:00:00 2001 From: Hironsan Date: Thu, 27 Jan 2022 11:41:51 +0900 Subject: [PATCH] Rename Relation model --- ...002_rename_annotationrelations_relation.py | 20 +++++++++++++++++++ backend/labels/models.py | 2 +- backend/labels/serializers.py | 4 ++-- backend/labels/views.py | 6 +++--- 4 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 backend/labels/migrations/0002_rename_annotationrelations_relation.py diff --git a/backend/labels/migrations/0002_rename_annotationrelations_relation.py b/backend/labels/migrations/0002_rename_annotationrelations_relation.py new file mode 100644 index 00000000..f23d31bb --- /dev/null +++ b/backend/labels/migrations/0002_rename_annotationrelations_relation.py @@ -0,0 +1,20 @@ +# Generated by Django 3.2.11 on 2022-01-27 02:39 + +from django.conf import settings +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0031_auto_20220127_0032'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('labels', '0001_initial'), + ] + + operations = [ + migrations.RenameModel( + old_name='AnnotationRelations', + new_name='Relation', + ), + ] diff --git a/backend/labels/models.py b/backend/labels/models.py index 8c0c8716..6f46ca5d 100644 --- a/backend/labels/models.py +++ b/backend/labels/models.py @@ -104,7 +104,7 @@ class TextLabel(Annotation): ) -class AnnotationRelations(models.Model): +class Relation(models.Model): annotation_id_1 = models.IntegerField() annotation_id_2 = models.IntegerField() type = models.ForeignKey(RelationTypes, related_name='annotation_relations', on_delete=models.CASCADE) diff --git a/backend/labels/serializers.py b/backend/labels/serializers.py index d3d04a57..e87c66b8 100644 --- a/backend/labels/serializers.py +++ b/backend/labels/serializers.py @@ -1,7 +1,7 @@ from rest_framework import serializers from api.models import CategoryType, Example, SpanType -from .models import Category, Span, TextLabel, AnnotationRelations +from .models import Category, Span, TextLabel, Relation class CategorySerializer(serializers.ModelSerializer): @@ -65,5 +65,5 @@ class RelationSerializer(serializers.ModelSerializer): return super().validate(attrs) class Meta: - model = AnnotationRelations + model = Relation fields = ('id', 'annotation_id_1', 'annotation_id_2', 'type', 'user', 'timestamp') diff --git a/backend/labels/views.py b/backend/labels/views.py index 3a0715b5..8f031b43 100644 --- a/backend/labels/views.py +++ b/backend/labels/views.py @@ -7,7 +7,7 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from api.models import Project -from labels.models import Category, Span, TextLabel, AnnotationRelations +from labels.models import Category, Span, TextLabel, Relation from members.permissions import IsInProjectOrAdmin, IsInProjectReadOnlyOrAdmin from .permissions import CanEditAnnotation from .serializers import CategorySerializer, SpanSerializer, TextLabelSerializer, RelationSerializer @@ -114,12 +114,12 @@ class RelationList(generics.ListCreateAPIView): def delete(self, request, *args, **kwargs): delete_ids = request.data['ids'] - AnnotationRelations.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 = AnnotationRelations.objects.all() + queryset = Relation.objects.all() serializer_class = RelationSerializer lookup_url_kwarg = 'annotation_relation_id' permission_classes = [IsAuthenticated & IsInProjectReadOnlyOrAdmin]