Skip to content

Commit 75f505b

Browse files
committed
upgrades to admin: search_fields, list_filters and raw_id_field
1 parent 78feec8 commit 75f505b

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

oauth2_provider/admin.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from django.contrib import admin
2+
from django.contrib.auth import get_user_model
23

34
from oauth2_provider.models import (
45
get_access_token_admin_class,
@@ -13,6 +14,8 @@
1314
get_refresh_token_model,
1415
)
1516

17+
has_email = hasattr(get_user_model(), 'email')
18+
1619

1720
class 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

3338
class GrantAdmin(admin.ModelAdmin):
@@ -37,12 +42,18 @@ class GrantAdmin(admin.ModelAdmin):
3742

3843
class 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

4352
class 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

4859
application_model = get_application_model()

0 commit comments

Comments
 (0)