Skip to content

Commit 81af906

Browse files
committed
Modify admin to allow listing history when instance has been deleted
1 parent ee826c0 commit 81af906

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changes
22
=======
33

4+
tip (unreleased)
5+
----------------
6+
- Add ability to list history in admin when the object instance is deleted. (gh-72)
7+
48
1.6.3 (2015-07-30)
59
------------------
610
- Respect `to_field` and `db_column` parameters (gh-182)

simple_history/admin.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from django.contrib.admin import helpers
77
from django.contrib.contenttypes.models import ContentType
88
from django.core.urlresolvers import reverse
9+
from django.http import Http404
910
from django.shortcuts import get_object_or_404, render
1011
from django.utils.text import capfirst
1112
from django.utils.html import mark_safe
@@ -56,7 +57,13 @@ def history_view(self, request, object_id, extra_context=None):
5657
object_id = unquote(object_id)
5758
action_list = history.filter(**{pk_name: object_id})
5859
# If no history was found, see whether this object even exists.
59-
obj = get_object_or_404(model, pk=object_id)
60+
try:
61+
obj = model.objects.get(**{pk_name: object_id})
62+
except model.DoesNotExist:
63+
try:
64+
obj = action_list.latest('history_date').instance
65+
except action_list.model.DoesNotExist:
66+
raise Http404
6067
content_type = ContentType.objects.get_by_natural_key(
6168
*USER_NATURAL_KEY)
6269
admin_user_view = 'admin:%s_%s_change' % (content_type.app_label,

0 commit comments

Comments
 (0)