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.

113 lines
3.1 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. from rest_framework import serializers
  2. from .models import BoundingBox, Category, Relation, Segmentation, Span, TextLabel
  3. from examples.models import Example
  4. from label_types.models import CategoryType, RelationType, SpanType
  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. example = serializers.PrimaryKeyRelatedField(queryset=Example.objects.all())
  53. type = serializers.PrimaryKeyRelatedField(queryset=RelationType.objects.all())
  54. class Meta:
  55. model = Relation
  56. fields = ("id", "prob", "user", "example", "created_at", "updated_at", "from_id", "to_id", "type")
  57. read_only_fields = ("user",)
  58. class BoundingBoxSerializer(serializers.ModelSerializer):
  59. example = serializers.PrimaryKeyRelatedField(queryset=Example.objects.all())
  60. label = serializers.PrimaryKeyRelatedField(queryset=CategoryType.objects.all())
  61. class Meta:
  62. model = BoundingBox
  63. fields = (
  64. "id",
  65. "uuid",
  66. "prob",
  67. "user",
  68. "example",
  69. "created_at",
  70. "updated_at",
  71. "label",
  72. "x",
  73. "y",
  74. "width",
  75. "height",
  76. )
  77. read_only_fields = ("user",)
  78. class SegmentationSerializer(serializers.ModelSerializer):
  79. example = serializers.PrimaryKeyRelatedField(queryset=Example.objects.all())
  80. label = serializers.PrimaryKeyRelatedField(queryset=CategoryType.objects.all())
  81. class Meta:
  82. model = Segmentation
  83. fields = (
  84. "id",
  85. "uuid",
  86. "prob",
  87. "user",
  88. "example",
  89. "created_at",
  90. "updated_at",
  91. "label",
  92. "points",
  93. )
  94. read_only_fields = ("user",)