11from django .contrib import admin
2+ from django .contrib .auth import get_user_model
23
34from oauth2_provider .models import (
45 get_access_token_admin_class ,
1314 get_refresh_token_model ,
1415)
1516
17+ has_email = hasattr (get_user_model (), 'email' )
18+
1619
1720class ApplicationAdmin (admin .ModelAdmin ):
1821 list_display = ("id" , "name" , "user" , "client_type" , "authorization_grant_type" )
@@ -28,6 +31,8 @@ class AccessTokenAdmin(admin.ModelAdmin):
2831 list_display = ("token" , "user" , "application" , "expires" )
2932 list_select_related = ("application" , "user" )
3033 raw_id_fields = ("user" , "source_refresh_token" )
34+ search_fields = ("token" ,) + (("user__email" ,) if has_email else ())
35+ list_filter = ("application" ,)
3136
3237
3338class GrantAdmin (admin .ModelAdmin ):
@@ -37,12 +42,18 @@ class GrantAdmin(admin.ModelAdmin):
3742
3843class IDTokenAdmin (admin .ModelAdmin ):
3944 list_display = ("jti" , "user" , "application" , "expires" )
40- raw_id_fields = ("user" ,)
45+ raw_id_fields = ("user" , )
46+ search_fields = ("token" ,) + (("user__email" ,) if has_email else ())
47+ list_filter = ("application" ,)
48+
49+
4150
4251
4352class RefreshTokenAdmin (admin .ModelAdmin ):
4453 list_display = ("token" , "user" , "application" )
4554 raw_id_fields = ("user" , "access_token" )
55+ search_fields = ("token" ,) + (("user__email" ,) if has_email else ())
56+ list_filter = ("application" ,)
4657
4758
4859application_model = get_application_model ()
0 commit comments