X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/099458fdc499ac939a42af27c0df30afcdff55e9..6fdea282117c9e066e714d714d3c14efadbca335:/src/catalogue/api/serializers.py diff --git a/src/catalogue/api/serializers.py b/src/catalogue/api/serializers.py index d52959b92..9baba3461 100644 --- a/src/catalogue/api/serializers.py +++ b/src/catalogue/api/serializers.py @@ -24,7 +24,20 @@ class TagDetailSerializer(serializers.ModelSerializer): class Meta: model = Tag - fields = ['name', 'url', 'sort_key', 'description'] + fields = [ + 'name', 'url', 'sort_key', + 'description', + 'description_pl', + 'plural', 'genre_epoch_specific', + 'adjective_feminine_singular', 'adjective_nonmasculine_plural', + 'genitive', 'collective_noun', + ] + write_only_fields = [ + 'description_pl', + 'plural', 'genre_epoch_specific', + 'adjective_feminine_singular', 'adjective_nonmasculine_plural', + 'genitive', 'collective_noun', + ] class TranslatorSerializer(serializers.Serializer): @@ -106,11 +119,12 @@ class BookDetailSerializer(LegacyMixin, serializers.ModelSerializer): class Meta: model = Book fields = [ - 'title', 'url', + 'title', 'url', 'language', 'epochs', 'genres', 'kinds', 'authors', 'translators', 'fragment_data', 'children', 'parent', 'preview', 'epub', 'mobi', 'pdf', 'html', 'txt', 'fb2', 'xml', 'media', 'audio_length', - 'cover_color', 'simple_cover', 'cover_thumb', 'cover', 'simple_thumb' + 'cover_color', 'simple_cover', 'cover_thumb', 'cover', 'simple_thumb', + 'isbn_pdf', 'isbn_epub', 'isbn_mobi', ] legacy_non_null_fields = ['html', 'txt', 'fb2', 'epub', 'mobi', 'pdf', 'cover', 'simple_cover', 'cover_thumb', 'simple_thumb'] @@ -146,12 +160,31 @@ class CollectionListSerializer(serializers.ModelSerializer): class CollectionSerializer(serializers.ModelSerializer): - books = BookSerializer(many=True, source='get_books') + books = BookSerializer(many=True, source='get_books', read_only=True) + authors = TagSerializer(many=True, read_only=True) + book_slugs = serializers.CharField(write_only=True, required=False) + author_slugs = serializers.CharField(write_only=True, required=False) url = AbsoluteURLField() class Meta: model = Collection - 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 class FragmentSerializer(serializers.ModelSerializer):