1
1
from django .contrib import admin
2
+ from django .contrib .auth import get_user_model
2
3
3
4
from oauth2_provider .models import (
4
5
get_access_token_admin_class ,
13
14
get_refresh_token_model ,
14
15
)
15
16
17
+ has_email = hasattr (get_user_model (), 'email' )
18
+
16
19
17
20
class ApplicationAdmin (admin .ModelAdmin ):
18
21
list_display = ("id" , "name" , "user" , "client_type" , "authorization_grant_type" )
@@ -28,6 +31,8 @@ class AccessTokenAdmin(admin.ModelAdmin):
28
31
list_display = ("token" , "user" , "application" , "expires" )
29
32
list_select_related = ("application" , "user" )
30
33
raw_id_fields = ("user" , "source_refresh_token" )
34
+ search_fields = ("token" ,) + (("user__email" ,) if has_email else ())
35
+ list_filter = ("application" ,)
31
36
32
37
33
38
class GrantAdmin (admin .ModelAdmin ):
@@ -37,12 +42,18 @@ class GrantAdmin(admin.ModelAdmin):
37
42
38
43
class IDTokenAdmin (admin .ModelAdmin ):
39
44
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
+
41
50
42
51
43
52
class RefreshTokenAdmin (admin .ModelAdmin ):
44
53
list_display = ("token" , "user" , "application" )
45
54
raw_id_fields = ("user" , "access_token" )
55
+ search_fields = ("token" ,) + (("user__email" ,) if has_email else ())
56
+ list_filter = ("application" ,)
46
57
47
58
48
59
application_model = get_application_model ()
0 commit comments