Example #1
0
 def create(self, request):
     slr = ArticleSerializer(data=request.data, context={'request': request})
     if slr.is_valid():
         article = slr.save()
         return Response(slr.data)
     else:
         return Response(slr.errors, status=400)
Example #2
0
 def post(self, request, *args, **kwargs):
     slr = ArticleSerializer(data=request.data)
     if slr.is_valid():
         article = slr.save()
         return Response(slr.data)
     else:
         return Response(slr.errors, status=400)
Example #3
0
 def update(self, request, pk=None):
     article = get_object_or_404(Article, pk=pk)
     slr = ArticleSerializer(data=request.data, instance=article, context={'request': request})
     if slr.is_valid():
         article = slr.save()
         return Response(slr.data)
     else:
         return Response(slr.errors, status=400)
Example #4
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)
Example #5
0
    def put(self, request, *args, **kwargs):
        saved_article = get_object_or_404(Article.objects.all(), pk=pk)
        data = request.data.get('article')
        slr = ArticleSerializer(instance=saved_article, data=data, partial=True)

        if slr.is_valid(raise_exception=True):
            article_saved = slr.save()

        return JsonResponse(slr.data, safe=False)
Example #6
0
 def get(self, request, *args, **kwargs):
     if 'pk' in kwargs.keys():
         article = get_object_or_404(Article, pk=kwargs.get('pk'))
         slr = ArticleSerializer(article)
         return Response(slr.data)
     else:
         articles = Article.objects.all()
         slr = ArticleSerializer(articles, many=True)
         return Response(slr.data)
Example #7
0
 def get(self, request, *args, **kwargs):
     article = Article.objects.get(pk=kwargs['pk'])
     slr = ArticleSerializer(article=article)
     if slr.is_valid():
         article = slr.save()
         return JsonResponse(slr.data, safe=False)
     else:
         response = JsonResponse(slr.errors, safe=False)
         response.status_code = 400
         return response
Example #8
0
 def post(self, request, *args, **kwargs):
     data = json.loads(request.body)
     slr = ArticleSerializer(data=data)
     if slr.is_valid():
         slr.save()
         return JsonResponse(slr.data, safe=False)
     else:
         response = JsonResponse(slr.errors, safe=False)
         response.status_code = 400
         return response
Example #9
0
 def put(self, request, *args, **kwargs):
     object = get_object_or_404(Article, pk=kwargs.get('pk'))
     data = json.loads(request.body)
     slr = ArticleSerializer(data=data, instance=object)
     if slr.is_valid():
         slr.save()
         return JsonResponse(slr.data, safe=False)
     else:
         response = JsonResponse(slr.errors, safe=False)
         response.status_code = 400
         return response
Example #10
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
Example #11
0
 def get(self, request, *args, **kwargs):
     data = Article.objects.get(pk=kwargs['pk'])
     slr = ArticleSerializer(data=data)
     pk = slr.data['id']
     if slr.is_valid():
         data.delete()
         return HttpResponse(pk)
     else:
         response = JsonResponse(slr.errors, safe=False)
         response.status_code = 400
         return response
Example #12
0
 def get(self, request, *args, **kwargs):
     objects = get_object_or_404(Article, pk=pk)
     slr = ArticleSerializer(objects)
     return JsonResponse(slr.data, safe=False)
Example #13
0
 def get(self, request, *args, **kwargs):
     objects = Article.objects.all()
     slr = ArticleSerializer(objects, many=True)
     return JsonResponse(slr.data, safe=False)
Example #14
0
 def get(self, request, *args, **kwargs):
     objects = Article.objects.all()
     serializer = ArticleSerializer(objects, many=True)
     return Response(serializer.data)
Example #15
0
 def retrieve(self, request, pk=None):
     article = get_object_or_404(Article, pk=pk)
     slr = ArticleSerializer(article, context={'request': request})
     return Response(slr.data)
Example #16
0
 def list(self, request):
     objects = Article.objects.all()
     slr = ArticleSerializer(objects, many=True, context={'request': request})
     return Response(slr.data)
Example #17
0
 def get(self, request, *args, **kwargs):
     object = Article.objects.get(pk=self.kwargs['pk'])
     slr = ArticleSerializer(object)
     return JsonResponse(slr.data, safe=False)
Example #18
0
 def get(self, request, *args, **kwargs):
     article = Article.objects.get(pk=kwargs['pk'])
     slr = ArticleSerializer(article=article)
     article = slr.delete()
     return JsonResponse(pk=kwargs['pk'])
Example #19
0
 def get(self, request, *args, **kwargs):
     article = Article.objects.get(pk=kwargs['pk'])
     slr = ArticleSerializer(article, many=False)
     return JsonResponse(slr.data, safe=False)