From 4842ad1b6ae9a2d08cb479c5d254aa3276ea2352 Mon Sep 17 00:00:00 2001 From: Nikita Reznikov <63803175+rnv812@users.noreply.github.com> Date: Sat, 8 Apr 2023 11:56:49 +0300 Subject: [PATCH] Add username search field for TokenAdmin (#8927) (#8934) * Add username search field for TokenAdmin (#8927) * Sort imports in a proper order (#8927) --- rest_framework/authtoken/admin.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rest_framework/authtoken/admin.py b/rest_framework/authtoken/admin.py index e41eb0002..163328eb0 100644 --- a/rest_framework/authtoken/admin.py +++ b/rest_framework/authtoken/admin.py @@ -4,6 +4,7 @@ from django.contrib.admin.views.main import ChangeList from django.contrib.auth import get_user_model from django.core.exceptions import ValidationError from django.urls import reverse +from django.utils.translation import gettext_lazy as _ from rest_framework.authtoken.models import Token, TokenProxy @@ -23,6 +24,8 @@ class TokenChangeList(ChangeList): class TokenAdmin(admin.ModelAdmin): list_display = ('key', 'user', 'created') fields = ('user',) + search_fields = ('user__username',) + search_help_text = _('Username') ordering = ('-created',) actions = None # Actions not compatible with mapped IDs. autocomplete_fields = ("user",)