Esempio n. 1
0
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)
Esempio n. 2
0
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)
Esempio n. 3
0
def getPostByUserId(request, userid):
    if request.method == 'GET':
        queryset = Post.objects.all().filter(userid=userid)
        serializer = PostSerializer(queryset, many=True)
        return Response(serializer.data)
Esempio n. 4
0
def getAllPost(request, threadid):
    if request.method == 'GET':
        queryset = Post.objects.all().filter(threadid=threadid)
        serializer = PostSerializer(queryset, many=True)
        return Response(serializer.data)