Beispiel #1
0
 def post(self, request, post_id, format=None):
     form = CommentForm(request.POST)
     if form.is_valid():
         comment = CommentModel()
         comment.content = request.POST.get('content')
         comment.post = PostModel.objects.get(id=post_id)
         comment.author = request.user
         comment.save()
         serializer = CommentSerializer(comment)
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(form.errors, status=status.HTTP_400_BAD_REQUEST)