class BookDetailInfoSerializer(serializers.ModelSerializer):
    category = SingleLevelCategorySerializer()
    tags = TagSerializer(many=True)
    license = LicenseSerializer()
    details = BookDetailSerializer(many=True)
    book_note = serializers.SerializerMethodField()
    browse_auth = serializers.CharField(required=False,
                                        max_length=100,
                                        write_only=True)

    def get_book_note(self, serializer):
        book_notes_json = []
        book_notes = BookNoteInfo.objects.filter(book_id=serializer.id,
                                                 note_type=1)
        if book_notes:
            book_notes_json = BookNoteBaseInfoSerializer(
                book_notes,
                many=True,
                context={
                    'request': self.context['request']
                }).data
        return book_notes_json

    class Meta:
        model = BookInfo
        exclude = ('browse_password', )
Example #2
0
class ArticleDetailInfoSerializer(serializers.ModelSerializer):
    category = SingleLevelCategorySerializer()
    tags = TagSerializer(many=True)
    license = LicenseSerializer()
    details = ArticleDetailSerializer(many=True)
    browse_auth = serializers.CharField(required=False, max_length=100, write_only=True)

    class Meta:
        model = ArticleInfo
        exclude = ('browse_password', )
Example #3
0
class BookNoteDetialInfoSerializer(serializers.ModelSerializer):
    category = SingleLevelCategorySerializer()
    tags = TagSerializer(many=True)
    book = BookBaseInfoSerializer()
    license = LicenseSerializer()
    details = BookNoteDetialSerializer(many=True)
    browse_auth = serializers.CharField(required=False, max_length=100, write_only=True)

    class Meta:
        model = BookNoteInfo
        exclude = ('browse_password', 'browse_password_encrypt')