+class BookAPIView(RetrieveAPIView):
+ queryset = models.Book.objects.all()
+ lookup_field = 'slug'
+
+ class serializer_class(serializers.ModelSerializer):
+ class AuthorSerializer(serializers.ModelSerializer):
+ literal = serializers.CharField(source='name')
+
+ class Meta:
+ model = models.Author
+ fields = ['literal']
+
+ def category_serializer(m):
+ class CategorySerializer(serializers.ModelSerializer):
+ literal = serializers.CharField(source='name')
+ class Meta:
+ model = m
+ fields = ['literal']
+ return CategorySerializer
+
+ authors = AuthorSerializer(many=True)
+ translators = AuthorSerializer(many=True)
+ epochs = category_serializer(models.Epoch)(many=True)
+ kinds = category_serializer(models.Kind)(many=True)
+ genres = category_serializer(models.Genre)(many=True)
+
+ class Meta:
+ model = models.Book
+ fields = [
+ 'title',
+ 'authors',
+ 'translators',
+ 'epochs',
+ 'kinds',
+ 'genres',
+ 'scans_source',
+ 'text_source',
+ 'original_year',
+ 'pd_year',
+ ]
+