0
class StatusListSearchApi(mixins.CreateModelMixin,
    mixins.RetrieveModelMixin,
    mixins.UpdateModelMixin,
    mixins.DestroyModelMixin,
    ListAPIView):

    # queryset=status.objects.all()
    serializer_class=statusSerializer
    lookup_field='id'
        # return Response(serializer.datax)
    def get_queryset(self):
        request=self.request
        qs=status.objects.all()
        query=request.GET.get('q')
        if query is not None:
            qs=qs.filter(content__icontains=query)
        return qs

    def get_object(self):
        request=self.request
        passed_id=request.GET.get('id',None)
        queryset=self.get_queryset()
        obj=None
        if passed_id is not None:
            obj=get_object_or_404(queryset,id=passed_id)
            self.check_object_permissions(request,obj)
    def get(self,request,*args,**kwargs):
        passed_id=request.GET.get('id',None)
        if passed_id is not None:
            return self.retrieve(request,*args,**kwargs)
        return super().get(request,*args,**kwargs)
    def post(self,request,*args,**kwargs):
        return self.create(request,*args,**kwargs)
    def put(self,request,*args,**kwargs):
        return self.update(request,*args,**kwargs)
    def patch(self,request,*args,**kwargs):
        return self.update(request,*args,**kwargs)

    def delete(self,request,*args,**kwargs):
        return self.destroy(request,*args,**kwargs)

我尝试使用 mixin 序列化程序进行序列化,但是当我尝试在可浏览的 api 中使用 delete 时,我遇到了一个错误:

/api/list/ 'NoneType' 对象的 AttributeError 没有属性 'delete'

创建和检索工作正常,但更新和删除不起作用。

不知道是什么问题......

任何形式的帮助表示赞赏

4

0 回答 0