예제 #1
0
    def get_comment(self, obj):
        comments = {}
        for index, comment in enumerate(obj.get_comments):
            comments[str(index)] = CommentSerializer(comment).data

        return comments
예제 #2
0
 def comments(self, request, *args, **kwargs):
     article = self.get_object()
     serializer = CommentSerializer(article.comments.all(),
                                    many=True,
                                    context=self.get_serializer_context())
     return Response(serializer.data)
예제 #3
0
 def create(self, request, *args, **kwargs):
     serializer = CommentSerializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     serializer.save()
     return Response(serializer.data)
예제 #4
0
def getComments(versus):
    response = []
    for comment in Comment.objects.filter(versus=versus).order_by('-date'):
        response.append(CommentSerializer(comment).data)
    return (response)    
 def get_highlighted_comments(self,obj):
     request = self.context['request']
     comments = obj.comments.order_by('-id')[0:2]
     return CommentSerializer(comments, context={'request': request}, many=True).data
예제 #6
0
 def get(self, request, *args, **kwargs):
     comments = CommentSerializer(self.get_object().comments, many=True)
     comments_json = comments.data
     return Response(comments_json)
예제 #7
0
 def get_comments_data(self, obj):
     return CommentSerializer(obj.comments, many=True, read_only=True).data
예제 #8
0
파일: views.py 프로젝트: rheehot/fastdj
def get_comments_view(request, article_pk):
    object_to_return = get_object_or_404(Comment,
                                         article_id=article_pk).values()
    return Response(CommentSerializer(object_to_return).data)
예제 #9
0
class PostSerializer(serializers.ModelSerializer):
    comments = CommentSerializer(many=True, read_only=True)

    class Meta:
        model = Post
        fields = ('title', 'content', 'comments')
예제 #10
0
class ArticleCommentSerializer(serializers.ModelSerializer):
    comments = CommentSerializer(many=True)

    class Meta:
        model = Article
        fields = ('comments', )
예제 #11
0
 def get_related_comment(self,obj):
     comments = Comment.objects.all().filter(documentation=obj).order_by('-id')
     serializer = CommentSerializer(comments,many=True,context={'request': self.context['request']})
     return serializer.data
예제 #12
0
 def retrieve(self, request, *args, **kwargs):
     post = self.get_object()
     serializer = CommentSerializer(post.comments, many=True)
     return Response(serializer.data)
예제 #13
0
 def get_comment(self, obj):
     return CommentSerializer(obj.comment).data
예제 #14
0
 def get(self, request, title_pk, format=None):
     comment = self.get_object(title_pk)
     serializer = CommentSerializer(comment, many=True)
     return Response(serializer.data)
예제 #15
0
 def get(self,request):
     comment_objects = Comment.objects.all()
     print(list(comment_objects)) # to convert queryset to list of objects, queryset is lazy, it has to be iterred thorugh so as to get the objects which can serialized
     serialized_comment_objects = CommentSerializer(comment_objects, many=True)
     return Response(serialized_comment_objects.data)
예제 #16
0
 def get(self,request,comment_id):
     comment_object = get_object_or_404(Comment,pk=comment_id)
     serialized_comment_object = CommentSerializer(comment_object)
     return Response(serialized_comment_object.data)