Exemplo n.º 1
0
 def put(self, request, pk):
     driver = Driver.objects.get(pk=pk)
     serializer = DriverSerializer(driver, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 2
0
 def post(self, request, format=None):
     queryset = Driver.objects.all()
     serializer = DriverSerializer(data=request.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)
Exemplo n.º 3
0
 def put(self, request, pk):
     driver = Driver.objects.filter(pk=pk[0])
     serializer = DriverSerializer(driver, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 4
0
 def post(self, request, format=None):
     queryset = Driver.objects.all()
     serializer = DriverSerializer(data=request.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)
Exemplo n.º 5
0
 def post(self, request):
     data = request.data
     try:
         driver_instance = Driver.objects.get(
             driver_email=data['driver_email'],
             driver_phoneno=data['driver_phoneno'])
     except Driver.DoesNotExist as ex:
         driver_instance = None
     if driver_instance:
         return Response({"error": 'Driver already exists'}, status=400)
     serializer = DriverSerializer(data=data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=201)
     return Response(serializer.errors, status=400)
Exemplo n.º 6
0
 def get(self, request, id):
     try:
         driver = self.get_object(id)
         serializer = DriverSerializer(driver)
         return Response(serializer, status=200)
     except Driver.DoesNotExist as ex:
         return Response({"error : driver does not exist"}, status=404)
Exemplo n.º 7
0
    def get(self, request, id):
        try:
            driver = self.get_object(id)
            driver_serializer = DriverSerializer(driver)
            rides = Ride_Details.objects.filter(driver_id=id)
            ride_serializer = Ride_DetailsSerializer(rides)
            return Response(ride_serializer.data, status=200)
            # return Response(serializer, status=200)

        except Ride_Details.DoesNotExist as ex:
            return Response({"error : Ride for this driver does not exist"},
                            status=404)
Exemplo n.º 8
0
 def get(self, request, format=None):
     drivers = Driver.objects.all()
     serializer = DriverSerializer(drivers,
                                   many=True,
                                   context={'request': request})
     return Response(serializer.data)
Exemplo n.º 9
0
 def get(self, request, pk):
     driver = Driver.objects.filter(pk=pk[0])
     serializer = DriverSerializer(driver,
                                   many=True,
                                   context={'request': request})
     return Response(serializer.data)