From 7a65a585fd9685bdc990d0108e2ba154df490d83 Mon Sep 17 00:00:00 2001 From: Tim Hawes Date: Tue, 26 Sep 2023 21:25:26 +0100 Subject: [PATCH] nfctokens: link to token and user objects in NFCTokenLog list --- nfctokens/admin.py | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/nfctokens/admin.py b/nfctokens/admin.py index 320d312..64eeac6 100644 --- a/nfctokens/admin.py +++ b/nfctokens/admin.py @@ -1,10 +1,12 @@ -# SPDX-FileCopyrightText: 2022 Tim Hawes +# SPDX-FileCopyrightText: 2022-2023 Tim Hawes # # 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( + '{}'.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( + '{}'.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