def put(self, request, pk): advert = self.get_object(pk) serializer = AdvertModelSerializer(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 advert_detail(self, pk): try: return Advert.objects.get(id=pk) except Advert.DoesNotExist: raise Http404 advert = self.get_object(pk) serializer= AdvertModelSerializer(advert) return Response(serializer.data) advert = self.get_object(pk) serializer = AdvertModelSerializer(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 post(self, request): serializer = AdvertModelSerializer(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)