Add a link to user in host admin, fix #440

This commit is contained in:
Fabian Weisshaar 2019-12-27 14:32:39 +01:00
parent daac6aeaee
commit bcae9584ff

View File

@ -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('<a href="{}">{}</a>'.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):