Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrades to admin: search_fields, list_filters and raw_id_field #1041

Merged
merged 4 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Paul Dekkers
Paul Oswald
Pavel Tvrdík
Peter Carnesciali
Petr Dlouhý
Rodney Richardson
Rustem Saiargaliev
Sandro Rodrigues
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* #967 OpenID: Add claims to Well know
* #1019 #1024 #1026 #1030 #1033 #1036 [pre-commit.ci] pre-commit autoupdate
* #1021 Jazzband: Synced file(s) with jazzband/.github
* #1041 Admin: make extensive fields raw_id, add search fields

## [Changed]
* #1022 Replaced pkg_resources usage with importlib.metadata
Expand Down
10 changes: 10 additions & 0 deletions oauth2_provider/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib import admin
from django.contrib.auth import get_user_model

from oauth2_provider.models import (
get_access_token_admin_class,
Expand All @@ -14,6 +15,9 @@
)


has_email = hasattr(get_user_model(), "email")


class ApplicationAdmin(admin.ModelAdmin):
list_display = ("id", "name", "user", "client_type", "authorization_grant_type")
list_filter = ("client_type", "authorization_grant_type", "skip_authorization")
Expand All @@ -28,6 +32,8 @@ class AccessTokenAdmin(admin.ModelAdmin):
list_display = ("token", "user", "application", "expires")
list_select_related = ("application", "user")
raw_id_fields = ("user", "source_refresh_token")
search_fields = ("token",) + (("user__email",) if has_email else ())
list_filter = ("application",)


class GrantAdmin(admin.ModelAdmin):
Expand All @@ -38,11 +44,15 @@ class GrantAdmin(admin.ModelAdmin):
class IDTokenAdmin(admin.ModelAdmin):
list_display = ("jti", "user", "application", "expires")
raw_id_fields = ("user",)
search_fields = ("token",) + (("user__email",) if has_email else ())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this valid? Searching from the admin now gives me django.core.exceptions.FieldError: Cannot resolve keyword 'token' into field. Choices are: access_token, application, application_id, created, expires, id, jti, scope, updated, user, user_id

list_filter = ("application",)


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


application_model = get_application_model()
Expand Down