diff --git a/app/db.sqlite3 b/app/db.sqlite3 index 3052730f..59e5e779 100644 Binary files a/app/db.sqlite3 and b/app/db.sqlite3 differ diff --git a/app/server/api.py b/app/server/api.py index 3d2f64c0..17b8ca54 100644 --- a/app/server/api.py +++ b/app/server/api.py @@ -89,7 +89,9 @@ class LabelDetail(generics.RetrieveUpdateDestroyAPIView): class DocumentList(generics.ListCreateAPIView): queryset = Document.objects.all() - serializer_class = DocumentSerializer + from .serializers import SequenceDocumentSerializer + # serializer_class = DocumentSerializer + serializer_class = SequenceDocumentSerializer filter_backends = (DjangoFilterBackend, filters.SearchFilter, filters.OrderingFilter) search_fields = ('text', ) permission_classes = (IsAuthenticated, IsProjectUser, IsAdminUserAndWriteOnly) diff --git a/app/server/serializers.py b/app/server/serializers.py index a00c643a..6e50f392 100644 --- a/app/server/serializers.py +++ b/app/server/serializers.py @@ -65,3 +65,19 @@ class Seq2seqAnnotationSerializer(serializers.ModelSerializer): class Meta: model = Seq2seqAnnotation fields = ('id', 'text') + + +class SequenceDocumentSerializer(serializers.ModelSerializer): + labels = SequenceAnnotationSerializer(source='seq_annotations', many=True) + annotations = serializers.SerializerMethodField() + + def get_annotations(self, obj): + request = self.context.get('request') + if request: + annotations = obj.seq_annotations.filter(user=request.user) + serializer = SequenceAnnotationSerializer(annotations.all(), many=True) + return serializer.data + + class Meta: + model = Document + fields = ('id', 'text', 'labels', 'annotations')