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.

70 lines
1.8 KiB

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