django-auditlog icon indicating copy to clipboard operation
django-auditlog copied to clipboard

Integrate AuditLog to default history page

Open wangxuepeng opened this issue 7 years ago • 6 comments

The core idea of Auditlog is similar to the log from Django’s admin. Unlike the log from Django’s admin (django.contrib.admin) Auditlog is much more flexible. Also, Auditlog saves a summary of the changes in JSON format, so changes can be tracked easily.

Considering this design purpose, it would be good to integrate or replace the default history view page with AuditLog log page, this will make the history page info more comprehensive and useful.

The implementation may need create a base ModelAdmin page and let all Admin page inherits it. It's better if the JSON changes can be shown in a beautiful format than the raw data.

Thanks.

wangxuepeng avatar Aug 18 '16 12:08 wangxuepeng

Good idea. If anyone wants to tackle this one, please do. (Otherwise it might take some time before I get to it.)

jjkester avatar Aug 18 '16 15:08 jjkester

Often i use a simple link to quickly get to related models, something like this could work:

def history_link(self):
    return u'<a href="{url}?id__exact={id}">{name}</a>'.format(
        url=reverse_lazy("admin:auditlog_logentry_changelist", args=()),
        id=self.id, name='history')

history_link.allow_tags = True
history_link.short_description = 'History'

Paul424 avatar May 24 '17 14:05 Paul424

Thanks @Paul424 for the idea. I added something similar in an admin mixin to redirect the history button, on the object detail page, to the auditlog list page, filtered by all versions of the object:

from django.contrib.contenttypes.models import ContentType
from django.http.response import HttpResponseRedirect
from django.urls import reverse

class HistoryModelAdminMixin:
    def history_view(self, request, object_id, extra_context=None):
        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,
            )
        )

Might be useful for some one.

joeribekker avatar Dec 15 '17 09:12 joeribekker

Hi, I'm new to Auditlog. Why not just extend the Django admin LogEntry? Right now, it seems a little redundant to me. Every time I make a change through the admin site, records are generated in both Auditlog LogEntry and Django admin. A couple of fields are recorded twice.

shifeitong avatar Mar 23 '20 07:03 shifeitong

@shifeitong The Admin site model is very limited and serves a different purpose. It logs only a message, where auditlog will log more details. Also, the the Admin site functionality is very much tied into the admin site. It will only log changes made there.

Keeping both active at the same time gives you the opportunity to see changes that were made by business logic in the application (logged by auditlog) and changes made through the admin (logged by both the admin and auditlog).

Adding a separate "audit" page next to the existing "history" page in the admin would provide the most value.

jjkester avatar Aug 31 '20 12:08 jjkester