Browse Source

Enable use api to filter by username

pull/1224/head
Hironsan 3 years ago
parent
commit
db1530f840
1 changed files with 8 additions and 5 deletions
  1. 13
      app/api/views/user.py

13
app/api/views/user.py

@ -1,4 +1,6 @@
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
@ -15,10 +17,11 @@ class Me(APIView):
return Response(serializer.data)
class Users(APIView):
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',)
def get(self, request, *args, **kwargs):
queryset = User.objects.all()
serialized_data = UserSerializer(queryset, many=True).data
return Response(serialized_data)
Loading…
Cancel
Save