Skip to content

Instantly share code, notes, and snippets.

@neoascetic
Created October 30, 2012 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neoascetic/3977938 to your computer and use it in GitHub Desktop.
Save neoascetic/3977938 to your computer and use it in GitHub Desktop.
[Django] Show recent user actions in his "History" view
{# Put this file into "admin/auth/user" folder under your templates directory #}
{% extends "admin/object_history.html" %}
{% load log i18n %}
{% block extrastyle %}
{{ block.super }}
<style>#log { width: 100%; } #log tbody th { width: 16em; }</style>
{% endblock %}
{% block content %}
{{ block.super }}
<h1>{% trans 'Recent actions' %}</h1>
{% get_admin_log 10 as admin_log for_user object %}
{% if not admin_log %}
<p>{% trans 'None found' %}</p>
{% else %}
<div class="module">
<table id="log">
<thead>
<tr>
<th scope="col">{% trans 'Date and time' %}</th>
<th scope="col">{% trans 'Action type' %}</th>
<tr>
</thead>
<tbody>
{% for entry in admin_log %}
<tr>
<th scope="row">
{{ entry.action_time|date:"DATE_FORMAT" }}
<br>
{{ entry.action_time|time:"TIME_FORMAT" }}
</th>
<td>
<i class="{% if entry.is_addition %}addlink{% elif entry.is_change %}changelink{% elif entry.is_deletion %}deletelink{% endif %}"></i>
{% if entry.is_deletion or not entry.get_admin_url %}
{{ entry.object_repr }}
{% else %}
<a href="{% url admin:index %}{{ entry.get_admin_url }}">{{ entry.object_repr }}</a>
{% endif %}
{% if entry.content_type %}
<i>({% filter capfirst %}{% trans entry.content_type.name %}{% endfilter %})</i>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment