Browse Source

Add serializer for sequence labeling

pull/10/head
Hironsan 6 years ago
parent
commit
b7beda5d6f
3 changed files with 19 additions and 1 deletions
  1. BIN
      app/db.sqlite3
  2. 4
      app/server/api.py
  3. 16
      app/server/serializers.py

BIN
app/db.sqlite3

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

16
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')
Loading…
Cancel
Save