Expose tag provider in image detail view
from rest_framework import serializers
from rest_framework.serializers import ModelSerializer
-
from cccatalog.api.models import Image
from cccatalog.api.serializers.search_serializers import ImageSerializer
+class ImageDetailTagSerializer(serializers.Serializer):
+ name = serializers.CharField(
+ required=True,
+ help_text="The name of a detailed tag."
+ )
+ accuracy = serializers.FloatField(
+ required=False,
+ help_text="The accuracy of a machine-generated tag. Human-generated "
+ "tags do not have an accuracy field."
+ )
+ provider = serializers.CharField(
+ required=False,
+ help_text="The source of a tag. Usually, it matches the provider of "
+ "the image, but it can also be generated by a third party."
+ )
+
+
class ImageDetailSerializer(ModelSerializer, ImageSerializer):
"""
A single image with some additional fields, such as view count. Unlike
@@ -15,6 +31,10 @@ class ImageDetailSerializer(ModelSerializer, ImageSerializer):
required=False,
help_text="The number of times that an image has been viewed. "
)
+ tags = ImageDetailTagSerializer(
+ many=True,
+ help_text="Tags with detailed metadata, such as accuracy and provider."
+ )
class Meta:
model = Image
