+ fields = [
+ 'url', 'books', 'description', 'title',
+ 'book_slugs', 'authors', 'author_slugs'
+ ]
+
+ def update(self, instance, validated_data):
+ instance = super().update(instance, validated_data)
+ author_slugs = validated_data.get('author_slugs', '').strip().split()
+ if author_slugs:
+ authors = Tag.objects.filter(
+ category='author',
+ slug__in=author_slugs
+ )
+ else:
+ authors = []
+ instance.authors.set(authors)
+ return instance
+
+
+class FragmentSerializer(serializers.ModelSerializer):
+ book = BookSerializer()
+ url = AbsoluteURLField()
+ href = AbsoluteURLField(source='get_api_url')
+
+ class Meta:
+ model = Fragment
+ fields = ['book', 'url', 'anchor', 'href']
+
+
+class FragmentDetailSerializer(serializers.ModelSerializer):
+ book = BookSerializer()
+ url = AbsoluteURLField()
+ themes = TagSerializer(many=True)
+
+ class Meta:
+ model = Fragment
+ fields = ['book', 'anchor', 'text', 'url', 'themes']