Ejemplo n.º 1
0
def rent_create(request):
    """
    Create a rent instance.
    """
    if request.method == 'POST':
        serializer = RentSerializer(data=request.data)
        #serializer.vehicle = Vehicle.objects.get(pk=request.data['vehicle']) queria fazer isso :-/
        #serializer.client = Client.objects.get(user=request.user)  // nao deu joguei o client no template X-|
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 2
0
def rent_create(request):
    """
    Create a rent instance.
    """   
    if request.method == 'POST':
        serializer = RentSerializer(data=request.data)       
        #serializer.vehicle = Vehicle.objects.get(pk=request.data['vehicle']) queria fazer isso :-/
        #serializer.client = Client.objects.get(user=request.user)  // nao deu joguei o client no template X-|
        if serializer.is_valid():            
            serializer.save()
            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 3
0
def rent_list(request):
    """
    List all code rents.
    """
    if request.method == 'GET':
        rents = Rent.objects.all()
        serializer = RentSerializer(rents, many=True)
        return JSONResponse(serializer.data)

    elif request.method == 'POST':
        data = JSONParser().parse(request)
        serializer = RentSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data, status=201)
        return JSONResponse(serializer.errors, status=400)
Ejemplo n.º 4
0
def rent_list(request):
    """
    List all code rents.
    """
    if request.method == 'GET':
        rents = Rent.objects.all()
        serializer = RentSerializer(rents, many=True)
        return JSONResponse(serializer.data)

    elif request.method == 'POST':
        data = JSONParser().parse(request)
        serializer = RentSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data, status=201)
        return JSONResponse(serializer.errors, status=400)