过滤器
from rest_framework.filters import BaseFilterBackend
class MineFilterBackend(BaseFilterBackend):
def filter_queryset(self, request, queryset, view):
user_id = request.user['id']
return queryset.filter(id=user_id)
使用
class UserInfoView(mixin.RetrieveModelMixin, GenericViewSet):
filter_backends = [MineFilterBackend]
queryset = models.UserInfo.objects.all()
serializer_class = account.UserInfoSerializer
标签:BaseFilterBackend,queryset,class,filter,user,自带,id,drf
From: https://www.cnblogs.com/sherwin1995/p/16971645.html