from django.contrib.auth.models import User from django_filters.rest_framework import DjangoFilterBackend from rest_framework import generics, filters from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView from projects.permissions import IsProjectAdmin from .serializers import UserSerializer class Me(APIView): permission_classes = (IsAuthenticated,) def get(self, request, *args, **kwargs): serializer = UserSerializer(request.user, context={"request": request}) return Response(serializer.data) class Users(generics.ListAPIView): queryset = User.objects.all() serializer_class = UserSerializer permission_classes = [IsAuthenticated & IsProjectAdmin] pagination_class = None filter_backends = (DjangoFilterBackend, filters.SearchFilter) search_fields = ("username",)