diff --git a/src/nsupdate/main/admin.py b/src/nsupdate/main/admin.py index 1997c1f..1316dd9 100644 --- a/src/nsupdate/main/admin.py +++ b/src/nsupdate/main/admin.py @@ -3,6 +3,8 @@ register our models for Django's admin """ from django.contrib import admin +from django.urls import reverse +from django.utils.safestring import mark_safe from .models import Host, RelatedHost, Domain, BlacklistedHost, ServiceUpdater, ServiceUpdaterHostConfig @@ -16,10 +18,19 @@ class DomainAdmin(admin.ModelAdmin): @admin.register(Host) class HostAdmin(admin.ModelAdmin): - list_display = ("name", "domain", "created_by", "client_faults", "api_auth_faults", "abuse", "abuse_blocked") + list_display = ("name", "domain", "created_by_link", "client_faults", "api_auth_faults", "abuse", "abuse_blocked") list_filter = ("created", "abuse", "abuse_blocked", "domain") + read_only_fields = ('created_by_link',) + search_fields = ("name", "created_by__username", "created_by__email") + def created_by_link(self, obj): + return mark_safe('{}'.format( + reverse("admin:auth_user_change", args=(obj.created_by.pk,)), + obj.created_by.username + )) + created_by_link.short_description = 'created by' + @admin.register(RelatedHost) class RelatedHostAdmin(admin.ModelAdmin):