I get error when I use the view's function, the bellow is my traceback:
File "/Users/xxx/Desktop/xxx/Project/xxx/qiyun_admin_usermanage/api/views.py", line 40, in <module>
class UserListAPIView(ListAPIView):
File "/Users/xxx/Desktop/xxx/Project/xxx/qiyun_admin_usermanage/api/views.py", line 59, in UserListAPIView
serializer_class = get_serializer_class()
TypeError: get_serializer_class() missing 1 required positional argument: 'self'
My views.py code ie bellow:
class UserListAPIView(ListAPIView):
"""
"""
queryset = User.objects.filter(is_admin=False, is_staff=False, is_superuser=False).exclude(status=4)
filter_backends = [SearchFilter, OrderingFilter]
search_fields = ['username', 'qq', 'email']
pagination_class = UserPageNumberPagination
class Meta:
ordering = ['-id']
def get_serializer_class(self):
if self.request.user.is_superuser:
return UserAdminListSerializer
else:
return UserListSerializer
serializer_class = get_serializer_class() # this is the line 59
And if I write this line serializer_class = get_serializer_class() to in the front of def get_serializer_class(self): method, I will
do not find error.