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)
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)