예제 #1
0
파일: cbv.py 프로젝트: Nusmailov/BFDjango
 def put(self, request, pk):
     advert = self.get_object(pk)
     serializer = RestaurantModelSerializer(instance=advert,
                                            data=request.data)
     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)
예제 #2
0
def rest_list(request, format=None):
    if request.method == 'GET':
        rests = Restaurant.objects.all()
        serializer = RestaurantModelSerializer(rests, many=True)
        return Response(serializer.data)
    elif request.method == 'POST':
        serializer = RestaurantModelSerializer(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)
예제 #3
0
def rest_detail(request, pk):
    try:
        rest = Restaurant.objects.get(id=pk)
    except Restaurant.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if request.method == 'GET':
        serializer = RestaurantModelSerializer(rest)
        return Response(serializer.data)
    elif request.method == 'PUT':
        serializer = RestaurantModelSerializer(instance=rest,
                                               data=request.data)
        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)
    elif request.method == 'DELETE':
        rest.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)
예제 #4
0
파일: cbv.py 프로젝트: Nusmailov/BFDjango
 def post(self, request):
     serializer = RestaurantModelSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save(owner=request.user)
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
예제 #5
0
파일: cbv.py 프로젝트: Nusmailov/BFDjango
 def get(self, request):
     dish = Dish.objects.all()
     serializer = RestaurantModelSerializer(rests, many=True)
     return Response(serializer.data)
예제 #6
0
파일: cbv.py 프로젝트: Nusmailov/BFDjango
 def get(self, request, pk):
     advert = self.get_object(pk)
     serializer = RestaurantModelSerializer(advert)
     return Response(serializer.data)
예제 #7
0
파일: cbv.py 프로젝트: Nusmailov/BFDjango
 def get(self, request):
     rests = Restaurant.objects.filter(owner=request.user)
     serializer = RestaurantModelSerializer(rests, many=True)
     return Response(serializer.data)