Adds API filtering for the "user" list

This commit is contained in:
Oliver 2021-11-08 16:53:15 +11:00
parent 3d553cf7de
commit ca0619a482

View File

@ -7,15 +7,16 @@ from django.core.exceptions import ObjectDoesNotExist
from django.conf.urls import url, include from django.conf.urls import url, include
from rest_framework import generics, permissions from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import filters, generics, permissions
from rest_framework.views import APIView from rest_framework.views import APIView
from rest_framework.authtoken.models import Token from rest_framework.authtoken.models import Token
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework import status from rest_framework import status
from .serializers import UserSerializer, OwnerSerializer from users.models import RuleSet, Owner, check_user_role
from users.serializers import UserSerializer, OwnerSerializer
from .models import RuleSet, Owner, check_user_role
class OwnerList(generics.ListAPIView): class OwnerList(generics.ListAPIView):
@ -127,6 +128,18 @@ class UserList(generics.ListAPIView):
serializer_class = UserSerializer serializer_class = UserSerializer
permission_classes = (permissions.IsAuthenticated,) permission_classes = (permissions.IsAuthenticated,)
filter_backends = [
DjangoFilterBackend,
filters.SearchFilter,
]
search_fields = [
'first_name',
'last_name',
'username',
]
class GetAuthToken(APIView): class GetAuthToken(APIView):
""" Return authentication token for an authenticated user. """ """ Return authentication token for an authenticated user. """