Skip to content

Commit 5779510

Browse files
committed
Revert "Removed history_user link from change admin page"
This reverts commit d5c7985.
1 parent 14880e5 commit 5779510

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

simple_history/admin.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
from django.utils.encoding import force_text
1919
except ImportError: # django 1.3 compatibility
2020
from django.utils.encoding import force_unicode as force_text
21+
from django.conf import settings
22+
23+
try:
24+
USER_NATURAL_KEY = settings.AUTH_USER_MODEL
25+
except AttributeError:
26+
USER_NATURAL_KEY = "auth.User"
27+
USER_NATURAL_KEY = tuple(key.lower() for key in USER_NATURAL_KEY.split('.', 1))
2128

2229

2330
class SimpleHistoryAdmin(admin.ModelAdmin):
@@ -52,6 +59,10 @@ def history_view(self, request, object_id, extra_context=None):
5259
action_list = history.filter(**{pk_name: object_id})
5360
# If no history was found, see whether this object even exists.
5461
obj = get_object_or_404(model, pk=object_id)
62+
content_type = ContentType.objects.get_by_natural_key(
63+
*USER_NATURAL_KEY)
64+
admin_user_view = 'admin:%s_%s_change' % (content_type.app_label,
65+
content_type.model)
5566
context = {
5667
'title': _('Change history: %s') % force_text(obj),
5768
'action_list': action_list,
@@ -60,6 +71,7 @@ def history_view(self, request, object_id, extra_context=None):
6071
'root_path': getattr(self.admin_site, 'root_path', None),
6172
'app_label': app_label,
6273
'opts': opts,
74+
'admin_user_view': admin_user_view
6375
}
6476
context.update(extra_context or {})
6577
return render(request, template_name=self.object_history_template,

simple_history/templates/simple_history/object_history.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<td>{{ action.get_history_type_display }}</td>
2929
<td>
3030
{% if action.history_user %}
31-
{{ action.history_user }}
31+
<a href="{% url admin_user_view action.history_user_id %}">{{ action.history_user }}</a>
3232
{% else %}
3333
None
3434
{% endif %}

0 commit comments

Comments
 (0)