from rest_framework.filters import BaseFilterBackend
class MenuFilterBackend(BaseFilterBackend):
def filter_queryset(self, request, queryset, view):
if request.method == "DELETE":
return queryset
folder = request.query_params.get("folder")
if not folder:
return queryset.none()
return queryset.filter(folder_id=folder)
class MenuModelSerializer(serializers.ModelSerializer):
class Meta:
model = models.Menu
fields = ["id", "title", 'name', "folder"]
class MenuView(BaseView, ModelViewSet):
authentication_classes = [JwtAuthentication]
permission_classes = [RbacPermission]
filter_backends = [MenuFilterBackend, ]
queryset = models.Menu.objects.all().order_by("-id")
serializer_class = MenuModelSerializer
标签:return,queryset,用法,filter,关于,id,folder,class
From: https://www.cnblogs.com/cloud-2-jane/p/18443292