Skip to content

Commit 39b44ac

Browse files
snps-msilvamjsir911
authored andcommitted
Fix list_display urls to point to /model/<id>/history
1 parent 3f38d97 commit 39b44ac

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
@@ -299,3 +299,24 @@ def queryset(self, request, queryset):
299299
if self.value():
300300
return queryset.model.history.filter(history_type='-').distinct()
301301
return queryset
302+
303+
304+
class YourModelAdmin(SimpleHistoryAdmin):
305+
def get_changelist(self, request, **kwargs):
306+
def url_from_result_maker(history=False):
307+
def custom_url_for_result(self, result):
308+
pk = getattr(result, self.pk_attname)
309+
from django.urls import reverse
310+
from django.contrib.admin.utils import quote
311+
route_type = 'history' if history else 'change'
312+
route = f'{self.opts.app_label}_{self.opts.model_name}_{route_type}'
313+
return reverse(f'admin:{route}',
314+
args=(quote(pk),),
315+
current_app=self.model_admin.admin_site.name)
316+
return custom_url_for_result
317+
changelist = super().get_changelist(request, **kwargs)
318+
if request.GET.get('entries', None) == 'deleted_only':
319+
changelist.url_for_result = url_from_result_maker(history=True)
320+
else:
321+
changelist.url_for_result = url_from_result_maker(history=False)
322+
return changelist

0 commit comments

Comments
 (0)