示例#1
0
    def post(self, request):
        """
        Creates a new Quota
        """
        data = request.data
        serializer = QuotaSerializer(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)
示例#2
0
    def patch(self, request, quota_id):
        """
        Partially updates the specified Quota
        """
        data = request.data
        quota = get_object_or_404(Quota, id=quota_id)
        serializer = QuotaSerializer(quota, 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)
示例#3
0
 def get(self, request, quota_id):
     """
     Return the specified Quota
     """
     quota = get_object_or_404(Quota, id=quota_id)
     serialized_data = QuotaSerializer(quota).data
     return Response(serialized_data)
示例#4
0
 def get(self, request):
     """
     Returns a list of all existing Quotas
     """
     quotas = Quota.objects.all()
     serialized_data = QuotaSerializer(quotas, many=True).data
     return Response(serialized_data)