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', )
Esempio n. 2
0
class BookBaseInfoSerializer(serializers.ModelSerializer):
    category = SingleLevelCategorySerializer()
    tags = TagSerializer(many=True)
    front_image = serializers.SerializerMethodField()
    book_image = serializers.SerializerMethodField()
    need_auth = serializers.SerializerMethodField()

    def get_front_image(self, book):
        if book.front_image:
            return "{0}/{1}".format(MEDIA_URL_PREFIX, book.front_image)

    def get_book_image(self, book):
        if book.book_image:
            return "{0}/{1}".format(MEDIA_URL_PREFIX, book.book_image)

    def get_need_auth(self, article):
        if article.browse_password_encrypt:
            return True
        else:
            return False

    class Meta:
        model = BookInfo
        fields = ('id', 'title', 'en_title', 'desc', 'en_desc', 'category',
                  'tags', 'click_num', 'like_num', 'comment_num', 'post_type',
                  'is_recommend', 'is_hot', 'is_banner', 'is_commentable',
                  'index', 'need_auth', 'front_image', 'front_image_type',
                  'is_reading', 'read_precentage', 'add_time', 'douban_id',
                  'douban_type', 'douban_infos', 'book_isbn10', 'book_isbn13',
                  'book_name', 'book_author', 'book_publisher', 'book_pages',
                  'book_url', 'book_image', 'book_rating', 'book_tags')
Esempio n. 3
0
class BookNoteBaseInfoSerializer2(serializers.ModelSerializer):
    category = SingleLevelCategorySerializer()
    tags = TagSerializer(many=True)
    browse_auth = serializers.CharField(required=False, max_length=100, write_only=True)

    class Meta:
        model = BookNoteInfo
        exclude = ('browse_password',)
Esempio n. 4
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', )
Esempio n. 5
0
class AlbumDetailInfoSerializer(serializers.ModelSerializer):
    category = SingleLevelCategorySerializer()
    pictures = PictureSerializer(many=True)
    tags = TagSerializer(many=True)
    browse_auth = serializers.CharField(required=False,
                                        max_length=100,
                                        write_only=True)

    class Meta:
        model = AlbumInfo
        exclude = ('browse_password', 'browse_password_encrypt')
Esempio n. 6
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')
Esempio n. 7
0
class MovieBaseInfoSerializer(serializers.ModelSerializer):
    category = SingleLevelCategorySerializer()
    front_image = serializers.SerializerMethodField()

    def get_front_image(self, movie):
        if movie.front_image:
            return "{0}/{1}".format(MEDIA_URL_PREFIX, movie.front_image)

    class Meta:
        model = MovieInfo
        fields = ('id', 'title', 'desc', 'directors', 'actors', 'category',
                  'post_type', 'is_recommend', 'is_hot', 'is_banner',
                  'browse_password_encrypt', 'front_image', 'add_time')
class BookBaseInfoSerializer(serializers.ModelSerializer):
    category = SingleLevelCategorySerializer()
    tags = TagSerializer(many=True)

    class Meta:
        model = BookInfo
        fields = ('id', 'title', 'desc', 'category', 'tags', 'post_type',
                  'is_recommend', 'is_hot', 'is_banner',
                  'browse_password_encrypt', 'front_image', 'is_reading',
                  'read_precentage', 'add_time', 'douban_id', 'douban_type',
                  'douban_infos', 'book_isbn10', 'book_isbn13', 'book_name',
                  'book_author', 'book_publisher', 'book_pages', 'book_url',
                  'book_image', 'book_rating', 'book_tags')
Esempio n. 9
0
class BookNoteBaseInfoSerializer1(serializers.ModelSerializer):
    category = SingleLevelCategorySerializer()
    tags = TagSerializer(many=True)
    sub_note = BookNoteBaseInfoSerializer2(many=True)
    browse_auth = serializers.CharField(required=False, max_length=100, write_only=True)
    front_image = serializers.SerializerMethodField()

    def get_front_image(self, book_note):
        if book_note.front_image:
            return "{0}/{1}".format(MEDIA_URL_PREFIX, book_note.front_image)

    class Meta:
        model = BookNoteInfo
        exclude = ('browse_password',)
Esempio n. 10
0
class BookNoteBaseInfoSerializer2(serializers.ModelSerializer):
    category = SingleLevelCategorySerializer()
    tags = TagSerializer(many=True)
    front_image = serializers.SerializerMethodField()
    need_auth = serializers.SerializerMethodField()

    def get_front_image(self, book_note):
        if book_note.front_image:
            return "{0}/{1}".format(MEDIA_URL_PREFIX, book_note.front_image)

    def get_need_auth(self, article):
        if article.browse_password_encrypt:
            return True
        else:
            return False

    class Meta:
        model = BookNoteInfo
        exclude = ('browse_password', 'browse_password_encrypt')
Esempio n. 11
0
class MovieBaseInfoSerializer(serializers.ModelSerializer):
    category = SingleLevelCategorySerializer()
    front_image = serializers.SerializerMethodField()
    need_auth = serializers.SerializerMethodField()

    def get_front_image(self, movie):
        if movie.front_image:
            return "{0}/{1}".format(MEDIA_URL_PREFIX, movie.front_image)

    def get_need_auth(self, article):
        if article.browse_password_encrypt:
            return True
        else:
            return False

    class Meta:
        model = MovieInfo
        fields = ('id', 'title', 'en_title', 'desc', 'en_desc', 'directors',
                  'actors', 'category', 'post_type', 'is_recommend', 'is_hot',
                  'is_banner', 'is_commentable', 'index', 'need_auth',
                  'front_image', 'add_time')