Skip to content

Commit 8e06dc0

Browse files
snps-msilvamjsir911
authored andcommitted
Fix list_display urls to point to /model/<id>/history
1 parent 2c71785 commit 8e06dc0

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

0 commit comments

Comments
 (0)