def put(self, request, pk, format=None): photo = self.get_object(pk) serializer = PhotoSerializer(photo, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.validated_data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def post(self, request, format=None): # print "request.data : ", request.data data = request.data data['owner'] = request.user.pk serializer = PhotoSerializer(data=data) if serializer.is_valid(): photoIntance = serializer.save(owner=request.user) print "photoIntance : ", photoIntance print 'serializer.validated_data : ', serializer.validated_data # return Response(serializer.validated_data, status=status.HTTP_201_CREATED) return Response("A photo is created", status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def get(self, request, pk, format=None): photo = self.get_object(pk) serializer = PhotoSerializer(photo) return Response(serializer.data)
def get(self, request, format=None): photo = Photo.objects.all() serializer = PhotoSerializer(photo, many=True) return Response(data=serializer.data, status=status.HTTP_200_OK)