Skip to content

Commit

Permalink
nfctokens: link to token and user objects in NFCTokenLog list
Browse files Browse the repository at this point in the history
  • Loading branch information
timhawes committed Sep 26, 2023
1 parent 0d9417f commit 7a65a58
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions nfctokens/admin.py
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

Expand Down Expand Up @@ -69,9 +71,9 @@ class NFCTokenLogAdmin(admin.ModelAdmin):
list_display = (
"timestamp",
"ltype",
"uid",
"token_link",
"location",
"name",
"user_link",
"token_description",
"authorized",
)
Expand All @@ -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
Expand Down

0 comments on commit 7a65a58

Please sign in to comment.