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)
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)
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)
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)
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)
def retrieve(self, request, *args, **kwargs): data = super().retrieve(request, *args, **kwargs).data return ApiResponse(data=data)
def list(self, request, *args, **kwargs): data = super().list(request, *args, **kwargs).data return ApiResponse(data=data)
def delete(self, request, *args, **kwargs): self.destroy(request, *args, **kwargs) return ApiResponse(http_status=status.HTTP_204_NO_CONTENT)
def patch(self, request, *args, **kwargs): data=request.data print(data) response = self.partial_update(request, *args, **kwargs) return ApiResponse(results=response.data)
def post(self,request,*args,**kwargs): data=self.create(request,*args,**kwargs) return ApiResponse(200,True,result=data.data)