Add username search field for TokenAdmin (#8927) (#8934)

* Add username search field for TokenAdmin (#8927)

* Sort imports in a proper order (#8927)
This commit is contained in:
Nikita Reznikov 2023-04-08 11:56:49 +03:00 committed by GitHub
parent 959085c145
commit 4842ad1b6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,6 +4,7 @@ from django.contrib.admin.views.main import ChangeList
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.urls import reverse from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from rest_framework.authtoken.models import Token, TokenProxy from rest_framework.authtoken.models import Token, TokenProxy
@ -23,6 +24,8 @@ class TokenChangeList(ChangeList):
class TokenAdmin(admin.ModelAdmin): class TokenAdmin(admin.ModelAdmin):
list_display = ('key', 'user', 'created') list_display = ('key', 'user', 'created')
fields = ('user',) fields = ('user',)
search_fields = ('user__username',)
search_help_text = _('Username')
ordering = ('-created',) ordering = ('-created',)
actions = None # Actions not compatible with mapped IDs. actions = None # Actions not compatible with mapped IDs.
autocomplete_fields = ("user",) autocomplete_fields = ("user",)