Exemple #1
0
 def put(self, request, *args, **kwargs):
     article = get_object_or_404(Article, pk=kwargs.get('pk'))
     slr = ArticleSerializer(data=request.data)
     if slr.is_valid():
         article =slr.update(article, slr.validated_data)
         return Response(slr.data)
     else:
         return Response(slr.errors, status=400)
Exemple #2
0
 def post(self, request, *args, **kwargs):
     data = json.loads(request.body)
     object = Article.objects.get(pk=self.kwargs['pk'])
     slr = ArticleSerializer(data=data, instance=object)
     if slr.is_valid():
         article = slr.update()
         return JsonResponse(slr.data, safe=False)
     else:
         response = JsonResponse(slr.errors, safe=False)
         response.status_code = 400
         return response