Esempio n. 1
0
 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)
Esempio n. 2
0
 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)
Esempio n. 3
0
 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)
Esempio n. 4
0
 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)
Esempio n. 5
0
 def get(self, request, pk, format=None):
     photo = self.get_object(pk)
     serializer = PhotoSerializer(photo)
     return Response(serializer.data)
Esempio n. 6
0
 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)