Browse Source

Rename Relation model

pull/1652/head
Hironsan 2 years ago
parent
commit
375604ba2a
4 changed files with 26 additions and 6 deletions
  1. 20
      backend/labels/migrations/0002_rename_annotationrelations_relation.py
  2. 2
      backend/labels/models.py
  3. 4
      backend/labels/serializers.py
  4. 6
      backend/labels/views.py

20
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',
),
]

2
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)

4
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')

6
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]
Loading…
Cancel
Save