def post(self, request): """ Creates a new Allocation """ data = request.DATA serializer = AllocationSerializer(data=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(self, request): """ Creates a new Allocation """ data = request.data serializer = AllocationSerializer(data=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 patch(self, request, quota_id): """ Partially updates the specified Allocation """ data = request.DATA allocation = get_object_or_404(Allocation, id=quota_id) serializer = AllocationSerializer(allocation, data=data, partial=True) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def patch(self, request, quota_id): """ Partially updates the specified Allocation """ data = request.data allocation = get_object_or_404(Allocation, id=quota_id) serializer = AllocationSerializer(allocation, data=data, partial=True) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def get(self, request, allocation_id): """ Fetch the specified Allocation """ allocation = get_object_or_404(Allocation, id=allocation_id) serialized_data = AllocationSerializer(allocation).data return Response(serialized_data)
def get(self, request): """ Returns a list of all existing Allocations """ quotas = Allocation.objects.all() serialized_data = AllocationSerializer(quotas, many=True).data return Response(serialized_data)