Creating object branched from object and setting the root object id to the parent_object field
With this function
def post(request, note_id, comment_id=None): """Create a comment under a post/idea.""" request.data["owner"] = request.user["id"] request.data["note_id"] = note_id if comment_id: try: parent_comment = Comment.objects.get(id=comment_id) request.data["parent_comment"] = parent_comment except Comment.DoesNotExist: request.data["parent_comment"] = None else: request.data["parent_comment"] = None serializer = CommentSerializer(data=request.data) if serializer.is_valid(raise_exception=True): serializer.save() return Response(serializer.data)
serializer for the comment model
class Meta: model = Comment fields = "__all__"
and my url path
path("<uuid:note_id>/comments/<uuid:comment_id>/replies/", views.CommentsGetOrCreateView.as_view(), name="CommentRepliesGetOrCreateView")
I'm trying to create Comment off of a Comment that is created off of a Note. Currently i can create a Note and create a Comment off of it and can retrieve comments under a comment but cant POST with the given url below as i need to. I currently get error on postman as ["parent_comment" : "Must be a valid UUID"]
I have tried reorganizing my post method and tried changing the serializer so the parent_comment can be null. Ive also tried adding .id at the end of "request.data["parent_comment"] = parent_comment.id"