def createPost(request): if request.method == 'PUT': serializer = PostSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def post(request, pk): if request.method == 'GET': queryset = Post.objects.get(pk=pk) serializer = PostSerializer(queryset) return Response(serializer.data) elif request.method == 'PUT': queryset = Post.objects.get(pk=pk) serializer = PostSerializer(queryset, data=request.data, partial=True) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def getPostByUserId(request, userid): if request.method == 'GET': queryset = Post.objects.all().filter(userid=userid) serializer = PostSerializer(queryset, many=True) return Response(serializer.data)
def getAllPost(request, threadid): if request.method == 'GET': queryset = Post.objects.all().filter(threadid=threadid) serializer = PostSerializer(queryset, many=True) return Response(serializer.data)