- fields = ['url', 'books', 'description', 'title']
+ 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