示例#1
0
 def post(self, request, format=None):
     serializer = InventorySerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         datas = serializer.data
         return Response(datas)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例#2
0
 def put(self, request, id, format=None):
     example = self.get_object(id)
     if example != False:
         serializer = InventorySerializer(example, data=request.data)
         if serializer.is_valid():
             serializer.save()
             datas = serializer.data
             return Response(datas)
         else:
             return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
     else:
         return Response(status=status.HTTP_400_BAD_REQUEST)
示例#3
0
 def get(self, request, id, format=None):
     example = self.get_object(id)
     if example != False:
         serializer = InventorySerializer(example)
         return Response(serializer.data)
     else:
         return Response(status=status.HTTP_400_BAD_REQUEST)
示例#4
0
 def get(self, request, format=None):
     queryset = Inventory.objects.all()
     serializer = InventorySerializer(queryset, many=True)
     return Response(serializer.data)