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

  1. from rest_framework import serializers
  2. from api.models import CategoryType, Example, SpanType
  3. from .models import Category, Span, TextLabel, Relation
  4. class CategorySerializer(serializers.ModelSerializer):
  5. label = serializers.PrimaryKeyRelatedField(queryset=CategoryType.objects.all())
  6. example = serializers.PrimaryKeyRelatedField(queryset=Example.objects.all())
  7. class Meta:
  8. model = Category
  9. fields = (
  10. 'id',
  11. 'prob',
  12. 'user',
  13. 'example',
  14. 'created_at',
  15. 'updated_at',
  16. 'label',
  17. )
  18. read_only_fields = ('user',)
  19. class SpanSerializer(serializers.ModelSerializer):
  20. label = serializers.PrimaryKeyRelatedField(queryset=SpanType.objects.all())
  21. example = serializers.PrimaryKeyRelatedField(queryset=Example.objects.all())
  22. class Meta:
  23. model = Span
  24. fields = (
  25. 'id',
  26. 'prob',
  27. 'user',
  28. 'example',
  29. 'created_at',
  30. 'updated_at',
  31. 'label',
  32. 'start_offset',
  33. 'end_offset',
  34. )
  35. read_only_fields = ('user',)
  36. class TextLabelSerializer(serializers.ModelSerializer):
  37. example = serializers.PrimaryKeyRelatedField(queryset=Example.objects.all())
  38. class Meta:
  39. model = TextLabel
  40. fields = (
  41. 'id',
  42. 'prob',
  43. 'user',
  44. 'example',
  45. 'created_at',
  46. 'updated_at',
  47. 'text',
  48. )
  49. read_only_fields = ('user',)
  50. class RelationSerializer(serializers.ModelSerializer):
  51. def validate(self, attrs):
  52. return super().validate(attrs)
  53. class Meta:
  54. model = Relation
  55. fields = ('id', 'annotation_id_1', 'annotation_id_2', 'type', 'user', 'timestamp')