Example #1
0
 def get(self,request,*args,**kwargs):
     print(kwargs.get('id'))
     if 'id' in kwargs:
         bt=self.retrieve(request,*args,**kwargs)
         return ApiResponse(200,True,result=bt.data)
     else:
         data=self.list(request,*args,**kwargs)
         return ApiResponse(200,True,result=data.data)
Example #2
0
 def get(self,request,*args,**kwargs):
     username=request.query_params.get('username')
     password=request.query_params.get('password')
     resu=User.objects.filter(username=username,password=password).first()
     if resu:
         data=UserSerializer(resu).data
         return ApiResponse(200,True,result=data)
     return ApiResponse(400,False)
Example #3
0
 def retrieve(self, request, *args, **kwargs):
     data = super().retrieve(request, *args, **kwargs).data
     pk = kwargs.get("pk")
     content = Article.objects.filter(id=pk, status=True).values()[0].get(
         "content", "")
     data.update({"content": content})
     return ApiResponse(data=data)
Example #4
0
    def show(self, request, *args, **kwargs):
        ids = request.GET.get("ids", "")
        ret = [
            ArticleTypeSerializer(q).data
            for q in ArticleType.objects.filter(id__in=ids.split(","))
        ]

        return ApiResponse(data=ret)
Example #5
0
 def post(self,request,*args,**kwargs):
     data=request.data
     # print(data)
     resu=UserSerializer(data=data)
     # t=resu.pop('pwds')
     # print(resu)
     resu.is_valid(raise_exception=True)
     obj=resu.save()
     # return ApiResponse('ok')
     return ApiResponse(200,True,result=UserSerializer(obj).data)
Example #6
0
 def retrieve(self, request, *args, **kwargs):
     data = super().retrieve(request, *args, **kwargs).data
     return ApiResponse(data=data)
Example #7
0
 def list(self, request, *args, **kwargs):
     data = super().list(request, *args, **kwargs).data
     return ApiResponse(data=data)
Example #8
0
 def delete(self, request, *args, **kwargs):
     self.destroy(request, *args, **kwargs)
     return ApiResponse(http_status=status.HTTP_204_NO_CONTENT)
Example #9
0
 def patch(self, request, *args, **kwargs):
     data=request.data
     print(data)
     response = self.partial_update(request, *args, **kwargs)
     return ApiResponse(results=response.data)
Example #10
0
 def post(self,request,*args,**kwargs):
     data=self.create(request,*args,**kwargs)
     return ApiResponse(200,True,result=data.data)