From ca0619a482126c894114f59d96736eaf0cd30e67 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 8 Nov 2021 16:53:15 +1100 Subject: [PATCH] Adds API filtering for the "user" list --- InvenTree/users/api.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/InvenTree/users/api.py b/InvenTree/users/api.py index 0bb51aab27..6b6b4afcfc 100644 --- a/InvenTree/users/api.py +++ b/InvenTree/users/api.py @@ -7,15 +7,16 @@ from django.core.exceptions import ObjectDoesNotExist 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.authtoken.models import Token from rest_framework.response import Response from rest_framework import status -from .serializers import UserSerializer, OwnerSerializer - -from .models import RuleSet, Owner, check_user_role +from users.models import RuleSet, Owner, check_user_role +from users.serializers import UserSerializer, OwnerSerializer class OwnerList(generics.ListAPIView): @@ -127,6 +128,18 @@ class UserList(generics.ListAPIView): serializer_class = UserSerializer permission_classes = (permissions.IsAuthenticated,) + filter_backends = [ + DjangoFilterBackend, + filters.SearchFilter, + ] + + search_fields = [ + 'first_name', + 'last_name', + 'username', + ] + + class GetAuthToken(APIView): """ Return authentication token for an authenticated user. """