From db1530f840a2363049fac6b1a0d088330c049f57 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Mon, 1 Mar 2021 08:00:53 +0900 Subject: [PATCH] Enable use api to filter by username --- app/api/views/user.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/api/views/user.py b/app/api/views/user.py index 2100ed5f..9767a007 100644 --- a/app/api/views/user.py +++ b/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)