Open wangxuepeng opened 8 years ago
Good idea. If anyone wants to tackle this one, please do. (Otherwise it might take some time before I get to it.)
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'
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.
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 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.
@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.
Good idea, I've extended the admin change form template and added the "Audit" link to Djangos object_tools
link list:
<!-- path/to/templates/admin/<app_name>/change_form.html -->
{% extends "admin/change_form.html" %}
{% load i18n admin_urls %}
{% block object-tools-items %}
<li>
<a href="{% url 'admin:auditlog_logentry_changelist' %}?object_pk={{ original.pk }}">
{% translate "Audit" %}
</a>
</li>
{{ block.super }}
{% endblock %}
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.