def get_comments(self, obj): content_type = obj.get_content_type obj_id = obj.id c_qs = Comment.objects.filter_by_instance(obj) return CommentSerializer(c_qs, many=True).data
def get_comments(self, obj): c_qs = Comment.objects.filter_by_instance(obj) comments = CommentSerializer(c_qs, many=True).data return comments
def get_comments(self, obj): c_qs = Comment.objects.filter_by_instance( obj) #comment_qs; filter_by_instance() also defined by ourselves comments = CommentSerializer(c_qs, many=True).data return comments
def post(self, request, pk: int): protest = get_object_or_404(Protest, pk=pk) comment = Comment.objects.create(protest=protest, user=request.user) return Response(CommentSerializer(comment).data, status=status.HTTP_201_CREATED)
def get_comment(self, obj): # content_type = obj.get_content_type # object_id = obj.id c_qs = Comment.objects.filter_by_instance(obj) comments = CommentSerializer(c_qs, many=True).data return comments
def get_comments(self, obj): queryset = Comment.objects.filter(parent=Status.objects.get(id=obj.id)) comments = CommentSerializer(queryset, many=True).data return comments
def to_representation(self, instance): ret = super(PublicationSerializer, self).to_representation(instance) comment_instance = Comments.objects.filter(commented_on=instance.pk) ret["comments"] = CommentSerializer(instance=comment_instance, many=True).data return ret
def test_serialize_comment(comment): serializer = CommentSerializer(comment) serializer.data # No errors
def get_comments(self, obj): c_qs = Comment.objects.filter(post=obj.id, parent_comment__isnull=True) comments = CommentSerializer(c_qs, many=True).data return comments
def get_comments(self, obj): return CommentSerializer(obj.comment_set.all(), many=True).data
from rest_framework.serializers import (HyperlinkedIdentityField,