diff --git a/backend/label_types/serializers.py b/backend/label_types/serializers.py index 154c6954..67def6e8 100644 --- a/backend/label_types/serializers.py +++ b/backend/label_types/serializers.py @@ -1,7 +1,7 @@ from rest_framework import serializers from rest_framework.exceptions import ValidationError -from .models import CategoryType, LabelType, RelationTypeOld, SpanType +from .models import CategoryType, LabelType, RelationType, SpanType class LabelSerializer(serializers.ModelSerializer): @@ -54,33 +54,16 @@ class LabelSerializer(serializers.ModelSerializer): class CategoryTypeSerializer(LabelSerializer): class Meta: model = CategoryType - fields = ( - "id", - "text", - "prefix_key", - "suffix_key", - "background_color", - "text_color", - ) + fields = LabelSerializer.Meta.fields class SpanTypeSerializer(LabelSerializer): class Meta: model = SpanType - fields = ( - "id", - "text", - "prefix_key", - "suffix_key", - "background_color", - "text_color", - ) - + fields = LabelSerializer.Meta.fields -class RelationTypesSerializer(serializers.ModelSerializer): - def validate(self, attrs): - return super().validate(attrs) +class RelationTypeSerializer(serializers.ModelSerializer): class Meta: - model = RelationTypeOld - fields = ("id", "color", "name") + model = RelationType + fields = LabelSerializer.Meta.fields diff --git a/backend/label_types/urls.py b/backend/label_types/urls.py index 4c60d9c8..f8b5cb25 100644 --- a/backend/label_types/urls.py +++ b/backend/label_types/urls.py @@ -21,5 +21,5 @@ urlpatterns = [ path(route="span-type-upload", view=SpanTypeUploadAPI.as_view(), name="span_type_upload"), path(route="relation_types", view=RelationTypeList.as_view(), name="relation_types_list"), path(route="relation_type-upload", view=RelationTypeUploadAPI.as_view(), name="relation_type-upload"), - path(route="relation_types/", view=RelationTypeDetail.as_view(), name="relation_type_detail"), + path(route="relation_types/", view=RelationTypeDetail.as_view(), name="relation_type_detail"), ] diff --git a/backend/label_types/views.py b/backend/label_types/views.py index 81a1445a..875cbc89 100644 --- a/backend/label_types/views.py +++ b/backend/label_types/views.py @@ -11,11 +11,11 @@ from rest_framework.response import Response from rest_framework.views import APIView from .exceptions import LabelValidationError -from .models import CategoryType, LabelType, RelationTypeOld, SpanType +from .models import CategoryType, LabelType, RelationType, SpanType from .serializers import ( CategoryTypeSerializer, LabelSerializer, - RelationTypesSerializer, + RelationTypeSerializer, SpanTypeSerializer, ) from projects.permissions import IsProjectAdmin, IsProjectStaffAndReadOnly @@ -74,14 +74,14 @@ class SpanTypeDetail(generics.RetrieveUpdateDestroyAPIView): class RelationTypeList(LabelList): - model = RelationTypeOld - serializer_class = RelationTypesSerializer + model = RelationType + serializer_class = RelationTypeSerializer class RelationTypeDetail(generics.RetrieveUpdateDestroyAPIView): - queryset = RelationTypeOld.objects.all() - serializer_class = RelationTypesSerializer - lookup_url_kwarg = "relation_type_id" + queryset = RelationType.objects.all() + serializer_class = RelationTypeSerializer + lookup_url_kwarg = "label_id" permission_classes = [IsAuthenticated & (IsProjectAdmin | IsProjectStaffAndReadOnly)] @@ -116,4 +116,4 @@ class SpanTypeUploadAPI(LabelUploadAPI): class RelationTypeUploadAPI(LabelUploadAPI): - serializer_class = RelationTypesSerializer + serializer_class = RelationTypeSerializer