-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nfctokens: link to token and user objects in NFCTokenLog list
- Loading branch information
Showing
1 changed file
with
31 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
# SPDX-FileCopyrightText: 2022 Tim Hawes <[email protected]> | ||
# SPDX-FileCopyrightText: 2022-2023 Tim Hawes <[email protected]> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
import datetime | ||
|
||
from django.contrib import admin | ||
from django.urls import reverse | ||
from django.utils.safestring import mark_safe | ||
|
||
from .models import NFCToken, NFCTokenLog | ||
|
||
|
@@ -69,9 +71,9 @@ class NFCTokenLogAdmin(admin.ModelAdmin): | |
list_display = ( | ||
"timestamp", | ||
"ltype", | ||
"uid", | ||
"token_link", | ||
"location", | ||
"name", | ||
"user_link", | ||
"token_description", | ||
"authorized", | ||
) | ||
|
@@ -90,6 +92,32 @@ class NFCTokenLogAdmin(admin.ModelAdmin): | |
"user__last_name", | ||
) | ||
|
||
def token_link(self, obj): | ||
if obj.token: | ||
return mark_safe( | ||
'<a href="{}">{}</a>'.format( | ||
reverse("admin:nfctokens_nfctoken_change", args=(obj.token.pk,)), | ||
obj.uid, | ||
) | ||
) | ||
else: | ||
return obj.uid | ||
|
||
token_link.short_description = "uid" | ||
|
||
def user_link(self, obj): | ||
if obj.user: | ||
return mark_safe( | ||
'<a href="{}">{}</a>'.format( | ||
reverse("admin:auth_user_change", args=(obj.user.pk,)), | ||
obj.name or obj.username, | ||
) | ||
) | ||
else: | ||
return obj.name or obj.username | ||
|
||
user_link.short_description = "user" | ||
|
||
|
||
class NFCTokenInline(admin.TabularInline): | ||
model = NFCToken | ||
|