Skip to content

Commit 26c16b9

Browse files
snps-msilvamjsir911
authored andcommitted
Fix list_display urls to point to /model/<id>/history
1 parent 6353514 commit 26c16b9

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

simple_history/admin.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,3 +297,24 @@ def queryset(self, request, queryset):
297297
if self.value():
298298
return queryset.model.history.filter(history_type="-").distinct()
299299
return queryset
300+
301+
302+
class YourModelAdmin(SimpleHistoryAdmin):
303+
def get_changelist(self, request, **kwargs):
304+
def url_from_result_maker(history=False):
305+
def custom_url_for_result(self, result):
306+
pk = getattr(result, self.pk_attname)
307+
from django.urls import reverse
308+
from django.contrib.admin.utils import quote
309+
route_type = 'history' if history else 'change'
310+
route = f'{self.opts.app_label}_{self.opts.model_name}_{route_type}'
311+
return reverse(f'admin:{route}',
312+
args=(quote(pk),),
313+
current_app=self.model_admin.admin_site.name)
314+
return custom_url_for_result
315+
changelist = super().get_changelist(request, **kwargs)
316+
if request.GET.get('entries', None) == 'deleted_only':
317+
changelist.url_for_result = url_from_result_maker(history=True)
318+
else:
319+
changelist.url_for_result = url_from_result_maker(history=False)
320+
return changelist

0 commit comments

Comments
 (0)