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)
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)
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)
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)
def get(self, request): dish = Dish.objects.all() serializer = RestaurantModelSerializer(rests, many=True) return Response(serializer.data)
def get(self, request, pk): advert = self.get_object(pk) serializer = RestaurantModelSerializer(advert) return Response(serializer.data)
def get(self, request): rests = Restaurant.objects.filter(owner=request.user) serializer = RestaurantModelSerializer(rests, many=True) return Response(serializer.data)