Beispiel #1
0
def auction_detail(request, pk):
    """
    Retrieve, update or delete a blog.
    """
    try:
        auction = Auction.objects.get(pk=pk)
    except Auction.DoesNotExist:
        return HttpResponse(status=404)

    if request.method == 'GET':
        serializer = AuctionSerializer(auction)
        return JSONResponse(serializer.data)

    elif request.method == 'POST':
        #data = JSONParser().parse(request)
        data = request.data
        print request.data
        serializer = AuctionSerializer(auction, data=data)
        if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data)
        else:
            return Response(serializer.errors, status=400)

    elif request.method == 'DELETE':
        auction.delete()
        return HttpResponse(status=204)
Beispiel #2
0
def auction_list(request):
    if request.method == 'GET':
        auctions = Auction.objects.all()
        serializer = AuctionSerializer(auctions, many=True)
        #print serializer.data
        #return JSONResponse(serializer.data)
        return Response(serializer.data)

    elif request.method == 'PUT':
        data = JSONParser().parse(request)
        serializer = AuctionSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data, status=201)
        else:
            return JSONResponse(serializer.errors, status=400)
Beispiel #3
0
 def get(self, request, pk):
     blog = self.get_object(pk)
     serializer = AuctionSerializer(blog)
     return Response(serializer.data)