class BlogReportSerialiizer(serializers.ModelSerializer): user = UserInfoSerializer(read_only=True) class Meta: ref_name = "blog 3" model = ReportDetail fields = "__all__"
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
class BlogLikesSerializer(serializers.ModelSerializer): user = UserInfoSerializer(read_only=True) class Meta: ref_name = "blog 2" model = BlogLikes fields = '__all__'
class GrouupReportSerialiizer(serializers.ModelSerializer): user = UserInfoSerializer(read_only=True) class Meta: ref_name = "group 5" model = MyBlogReportDetail fields = "__all__"
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
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()
class CommentChildSerializer(ModelSerializer): user = UserInfoSerializer(read_only=True) class Meta: model = Comment fields = [ 'id', 'user', 'content', 'timestamp', ]
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()
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()
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()
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()
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()
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
class SubCommentLikesSerializer(serializers.ModelSerializer): user = UserInfoSerializer(read_only=True) class Meta: model = SubCommentLikes fields = '__all__'
class MessageLikesSerializer(serializers.ModelSerializer): user = UserInfoSerializer(read_only=True) class Meta: model = MessageLikes fields = '__all__'
class ReportListSerializer(serializers.ModelSerializer): user = UserInfoSerializer(read_only=True) class Meta: model = Reports fields = '__all__'