Skip to content

Commit 2980117

Browse files
upgrades to admin: search_fields, list_filters and raw_id_field (#1041)
* upgrades to admin: search_fields, list_filters and raw_id_field * update CHANGELOG * add name to AUTHORS * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 78feec8 commit 2980117

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Paul Dekkers
4747
Paul Oswald
4848
Pavel Tvrdík
4949
Peter Carnesciali
50+
Petr Dlouhý
5051
Rodney Richardson
5152
Rustem Saiargaliev
5253
Sandro Rodrigues

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2525
* #967 OpenID: Add claims to Well know
2626
* #1019 #1024 #1026 #1030 #1033 #1036 [pre-commit.ci] pre-commit autoupdate
2727
* #1021 Jazzband: Synced file(s) with jazzband/.github
28+
* #1041 Admin: make extensive fields raw_id, add search fields
2829

2930
## [Changed]
3031
* #1022 Replaced pkg_resources usage with importlib.metadata

oauth2_provider/admin.py

Lines changed: 10 additions & 0 deletions
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,
@@ -14,6 +15,9 @@
1415
)
1516

1617

18+
has_email = hasattr(get_user_model(), "email")
19+
20+
1721
class ApplicationAdmin(admin.ModelAdmin):
1822
list_display = ("id", "name", "user", "client_type", "authorization_grant_type")
1923
list_filter = ("client_type", "authorization_grant_type", "skip_authorization")
@@ -28,6 +32,8 @@ class AccessTokenAdmin(admin.ModelAdmin):
2832
list_display = ("token", "user", "application", "expires")
2933
list_select_related = ("application", "user")
3034
raw_id_fields = ("user", "source_refresh_token")
35+
search_fields = ("token",) + (("user__email",) if has_email else ())
36+
list_filter = ("application",)
3137

3238

3339
class GrantAdmin(admin.ModelAdmin):
@@ -38,11 +44,15 @@ class GrantAdmin(admin.ModelAdmin):
3844
class IDTokenAdmin(admin.ModelAdmin):
3945
list_display = ("jti", "user", "application", "expires")
4046
raw_id_fields = ("user",)
47+
search_fields = ("token",) + (("user__email",) if has_email else ())
48+
list_filter = ("application",)
4149

4250

4351
class RefreshTokenAdmin(admin.ModelAdmin):
4452
list_display = ("token", "user", "application")
4553
raw_id_fields = ("user", "access_token")
54+
search_fields = ("token",) + (("user__email",) if has_email else ())
55+
list_filter = ("application",)
4656

4757

4858
application_model = get_application_model()

0 commit comments

Comments
 (0)