Esempio n. 1
0
class BlogReportSerialiizer(serializers.ModelSerializer):
    user = UserInfoSerializer(read_only=True)

    class Meta:
        ref_name = "blog 3"
        model = ReportDetail
        fields = "__all__"
Esempio n. 2
0
class BlogSerializer(serializers.ModelSerializer):
    reports = serializers.SerializerMethodField(read_only=True)
    likes = serializers.SerializerMethodField(read_only=True)
    comments = serializers.SerializerMethodField(read_only=True)
    user = UserInfoSerializer(read_only=True)

    class Meta:
        ref_name = "blog 1"
        model = Blog
        fields = '__all__'

    def get_reports(self, obj):
        return obj.reports.count()

    def get_likes(self, obj):
        return obj.likes.count()

    def get_comments(self, obj):
        comment = obj.comments.count()
        return comment

    def get_content(self, obj):
        content = obj.content
        if obj.is_reblog:
            content = obj.parent.content
            return content
Esempio n. 3
0
class BlogLikesSerializer(serializers.ModelSerializer):
    user = UserInfoSerializer(read_only=True)

    class Meta:
        ref_name = "blog 2"
        model = BlogLikes
        fields = '__all__'
Esempio n. 4
0
class GrouupReportSerialiizer(serializers.ModelSerializer):
    user = UserInfoSerializer(read_only=True)

    class Meta:
        ref_name = "group 5"
        model = MyBlogReportDetail
        fields = "__all__"
Esempio n. 5
0
class BlogSerializer(serializers.ModelSerializer):
    likes = serializers.SerializerMethodField(read_only=True)
    comment = serializers.SerializerMethodField(read_only=True)
    user = UserInfoSerializer(read_only=True)

    #parent = CreateBlogSerializer(read_only=True)

    class Meta:
        ref_name = "group 4"
        model = MyBlog
        exclude = ['report']

    def get_likes(self, obj):
        return obj.likes.count()

    def get_comment(self, obj):
        return obj.comment.count()

    def get_content(self, obj):
        content = obj
        if obj.is_reblog:
            content = obj.parent.content
            return content

    def get_title(self, obj):
        title = obj
        if obj.is_reblog:
            title = obj.parent.title
            return title
Esempio n. 6
0
class SubCommentSerializer(serializers.ModelSerializer):
    like = serializers.SerializerMethodField(read_only=True)
    user = UserInfoSerializer(read_only=True)

    class Meta:
        model = SubComment
        fields = '__all__'

    def get_like(self, obj):
        return obj.like.count()
Esempio n. 7
0
class CommentChildSerializer(ModelSerializer):
    user = UserInfoSerializer(read_only=True)

    class Meta:
        model = Comment
        fields = [
            'id',
            'user',
            'content',
            'timestamp',
        ]
Esempio n. 8
0
class CommentSerializer(serializers.ModelSerializer):
    like = serializers.SerializerMethodField(read_only=True)
    user = UserInfoSerializer(read_only=True)

    class Meta:
        ref_name = "group 4"
        model = MyComment
        fields = ["reference", "id", "comment", "likes", "created_at"]

    def get_like(self, obj):
        return obj.like.count()
Esempio n. 9
0
class MessageSerializer(serializers.ModelSerializer):
    like = serializers.SerializerMethodField(read_only=True)
    comments = serializers.SerializerMethodField(read_only=True)
    user = UserInfoSerializer(read_only=True)

    class Meta:
        model = Message
        fields = ["reference", "id", "comments", "like", "created_at", 'user']

    def get_like(self, obj):
        return obj.like.count()

    def get_comments(self, obj):
        return obj.comments.count()
Esempio n. 10
0
class GroupSerializer(serializers.ModelSerializer):
    users = serializers.SerializerMethodField(read_only=True)
    follower = serializers.SerializerMethodField(read_only=True)
    user = UserInfoSerializer(read_only=True)

    class Meta:
        model = Group
        exclude = ['request', 'admin']

    def get_follower(self, obj):
        return obj.follower.count()

    def get_users(self, obj):
        return obj.users.count()
Esempio n. 11
0
class CommentSerializer(serializers.ModelSerializer):
    like = serializers.SerializerMethodField(read_only=True)
    comment = serializers.SerializerMethodField(read_only=True)
    user = UserInfoSerializer(read_only=True)

    class Meta:
        ref_name = "blog 2"
        model = Comment
        fields = '__all__'

    def get_like(self, obj):
        return obj.like.count()

    def get_comment(self, obj):
        return obj.comment.count()
Esempio n. 12
0
class ReportSerializer(serializers.ModelSerializer):
    user = UserInfoSerializer(read_only=True)

    class Meta:
        model = MyBlog
        fields = '__all__'

    def get_report(self, obj):
        return obj.report.count()

    def get_likes(self, obj):
        return obj.likes.count()

    def get_comment(self, obj):
        return obj.comment.count()
Esempio n. 13
0
class CommentDetailSerializer(ModelSerializer):
    user = UserInfoSerializer(read_only=True)
    reply_count = SerializerMethodField()
    content_object_url = SerializerMethodField()
    replies = SerializerMethodField()

    class Meta:
        model = Comment
        fields = [
            'id',
            'user',
            #'content_type',
            #'object_id',
            'content',
            'reply_count',
            'replies',
            'timestamp',
            'content_object_url',
        ]
        read_only_fields = [
            #'content_type',
            #'object_id',
            'reply_count',
            'replies',
        ]

    def get_content_object_url(self, obj):
        try:
            return obj.content_object.get_api_url()
        except:
            return None

    def get_replies(self, obj):
        if obj.is_parent:
            return CommentChildSerializer(obj.children(), many=True).data
        return None

    def get_reply_count(self, obj):
        if obj.is_parent:
            return obj.children().count()
        return 0
Esempio n. 14
0
class SubCommentLikesSerializer(serializers.ModelSerializer):
    user = UserInfoSerializer(read_only=True)

    class Meta:
        model = SubCommentLikes
        fields = '__all__'
Esempio n. 15
0
class MessageLikesSerializer(serializers.ModelSerializer):
    user = UserInfoSerializer(read_only=True)

    class Meta:
        model = MessageLikes
        fields = '__all__'
Esempio n. 16
0
class ReportListSerializer(serializers.ModelSerializer):
    user = UserInfoSerializer(read_only=True)

    class Meta:
        model = Reports
        fields = '__all__'