From 2c71785d572d96d81d59607668f5f0d7ed9f4a5e Mon Sep 17 00:00:00 2001 From: Marco Silva Date: Tue, 2 Mar 2021 08:46:18 -0700 Subject: [PATCH] POC for #72 Note that if you are using any custom methods on the model for the admin display, you need to use a History Base class for this to work(#311). --- simple_history/admin.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/simple_history/admin.py b/simple_history/admin.py index 34e3033fe..45fe3353b 100644 --- a/simple_history/admin.py +++ b/simple_history/admin.py @@ -283,3 +283,16 @@ def enforce_history_permissions(self): return getattr( settings, "SIMPLE_HISTORY_ENFORCE_HISTORY_MODEL_PERMISSIONS", False ) + + +class SimpleHistoryShowDeletedFilter(admin.SimpleListFilter): + title = "Entries" + parameter_name = "entries" + + def lookups(self, request, model_admin): + return (("deleted_only", "Only Deleted"),) + + def queryset(self, request, queryset): + if self.value(): + return queryset.model.history.filter(history_type="-").distinct() + return queryset