Пример #1
0
 def post(self, request, format=None):
     serializer = PhotoSerializer(data=request.data, partial=True)
     if serializer.is_valid():
         obj = self.get_object(request.data['pk'])
         obj.delete()
         return Response(status=status.HTTP_200_OK)
     else:
         return Response(
             serializer.errors,
             status=status.HTTP_406_NOT_ACCEPTABLE
         )
Пример #2
0
 def post(self, request, pk):
     serializer = PhotoSerializer(data=request.data, partial=True)
     if serializer.is_valid():
         serializer.save()
     else:
         return Response(
             serializer.errors, status=status.HTTP_406_NOT_ACCEPTABLE
         )
     try:
         obj = Gallery.objects.get(pk=pk)
         obj.photos.add(serializer.instance)
         return Response(status=status.HTTP_201_CREATED)
     except:
         return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)