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)
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)
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)
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)
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)
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)
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
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
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
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
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
def get(self, request, *args, **kwargs): objects = get_object_or_404(Article, pk=pk) slr = ArticleSerializer(objects) return JsonResponse(slr.data, safe=False)
def get(self, request, *args, **kwargs): objects = Article.objects.all() slr = ArticleSerializer(objects, many=True) return JsonResponse(slr.data, safe=False)
def get(self, request, *args, **kwargs): objects = Article.objects.all() serializer = ArticleSerializer(objects, many=True) return Response(serializer.data)
def retrieve(self, request, pk=None): article = get_object_or_404(Article, pk=pk) slr = ArticleSerializer(article, context={'request': request}) return Response(slr.data)
def list(self, request): objects = Article.objects.all() slr = ArticleSerializer(objects, many=True, context={'request': request}) return Response(slr.data)
def get(self, request, *args, **kwargs): object = Article.objects.get(pk=self.kwargs['pk']) slr = ArticleSerializer(object) return JsonResponse(slr.data, safe=False)
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'])
def get(self, request, *args, **kwargs): article = Article.objects.get(pk=kwargs['pk']) slr = ArticleSerializer(article, many=False) return JsonResponse(slr.data, safe=False)