Adding a search field for Token section in Django Admin

Viewed 337

I'm using the Django rest framework and I need to manually delete a token that belongs to a specific user using the Django admin. But the problem is it's hard to find the relevant token of a user when there are thousands of tokens. So I need to add a search to the token section then I can search the token using the user's Email. How I can add an search for the token section in the Django admin.

1 Answers

Try this

admin.py:

from rest_framework.authtoken.models import Token

class FilterTokenAdmin(admin.ModelAdmin):
    search_fields = ['user__email','user__username']
admin.site.register(Token,FilterTokenAdmin)
Related