You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

69 lines
1.8 KiB

from rest_framework import serializers
from .models import Category, Relation, Span, TextLabel
from examples.models import Example
from label_types.models import CategoryType, SpanType
class CategorySerializer(serializers.ModelSerializer):
label = serializers.PrimaryKeyRelatedField(queryset=CategoryType.objects.all())
example = serializers.PrimaryKeyRelatedField(queryset=Example.objects.all())
class Meta:
model = Category
fields = (
"id",
"prob",
"user",
"example",
"created_at",
"updated_at",
"label",
)
read_only_fields = ("user",)
class SpanSerializer(serializers.ModelSerializer):
label = serializers.PrimaryKeyRelatedField(queryset=SpanType.objects.all())
example = serializers.PrimaryKeyRelatedField(queryset=Example.objects.all())
class Meta:
model = Span
fields = (
"id",
"prob",
"user",
"example",
"created_at",
"updated_at",
"label",
"start_offset",
"end_offset",
)
read_only_fields = ("user",)
class TextLabelSerializer(serializers.ModelSerializer):
example = serializers.PrimaryKeyRelatedField(queryset=Example.objects.all())
class Meta:
model = TextLabel
fields = (
"id",
"prob",
"user",
"example",
"created_at",
"updated_at",
"text",
)
read_only_fields = ("user",)
class RelationSerializer(serializers.ModelSerializer):
def validate(self, attrs):
return super().validate(attrs)
class Meta:
model = Relation
fields = ("id", "annotation_id_1", "annotation_id_2", "type", "user", "timestamp")