Enable auditlogging

This commit is contained in:
Seamus Johnston 2022-11-10 08:13:00 -06:00
parent a25dd16094
commit 349659be90
No known key found for this signature in database
GPG key ID: 2F21225985069105
7 changed files with 210 additions and 67 deletions

View file

@ -1,6 +1,25 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import User, UserProfile
from django.contrib.contenttypes.models import ContentType
from django.http.response import HttpResponseRedirect
from django.urls import reverse
from .models import User, UserProfile, DomainApplication, Website
class AuditedAdmin(admin.ModelAdmin):
"""Custom admin to make auditing easier."""
def history_view(self, request, object_id, extra_context=None):
"""On clicking 'History', take admin to the auditlog view for an object."""
return HttpResponseRedirect(
"{url}?resource_type={content_type}&object_id={object_id}".format(
url=reverse("admin:auditlog_logentry_changelist", args=()),
content_type=ContentType.objects.get_for_model(self.model).pk,
object_id=object_id,
)
)
class UserProfileInline(admin.StackedInline):
@ -18,3 +37,5 @@ class MyUserAdmin(UserAdmin):
admin.site.register(User, MyUserAdmin)
admin.site.register(DomainApplication, AuditedAdmin)
admin.site.register(Website, AuditedAdmin)