コード例 #1
0
ファイル: views.py プロジェクト: HALLOWe3n/StockCompsREST
 def post(self, request, version=None):
     # Deserializer data
     serializer = StockSerializer(data=request.data)
     print(request.data)
     # check
     if serializer.is_valid():
         # save to db
         serializer.save()
         # return status of success
         return Response({'status': 200}, status=201)
     # return status of failed
     return Response({'status': 400}, status=400)
コード例 #2
0
ファイル: Stock.py プロジェクト: aminhp93/2020-server
    def put(self, request, *args, **kwargs):
        url = "https://svr3.fireant.vn/api/Data/Markets/TradingStatistic"

        headers = {
            'cache-control': 'no-cache'
        }

        response = requests.request('GET', url, headers=headers)
        Stock.objects.all().delete()
        serializer = StockSerializer(data=response.json(), many=True)
        if not serializer.is_valid():
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
        created = serializer.save()
        return Response(serializer.data, status = status.HTTP_201_CREATED)
コード例 #3
0
 def partial_update(self, request, pk=None):
     stock = get_object_or_404(Stock, pk=pk)
     serializer = StockSerializer(stock, data=request.data, partial=True)
     serializer.is_valid(raise_exception=True)
     serializer.save()
     return Response(serializer.data)
コード例 #4
0
 def create(self, request):
     data = request.data
     serializer = StockSerializer(data=data)
     serializer.is_valid(raise_exception=True)
     serializer.save()
     return Response(serializer.data)