Skip to content

Commit

Permalink
Some simple tidying
Browse files Browse the repository at this point in the history
.distinct() -> .latest_of_each() prevents multiple deletes from adding
multiple rows for the same object.
  • Loading branch information
mjsir911 committed Apr 27, 2023
1 parent 95cebf5 commit 9b9bd0a
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions simple_history/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,7 @@ class SimpleHistoryChangeList(ChangeList):
def apply_select_related(self, qs):
# Our qs is different if we use the history, so the normal select_related
# won't work and results in an empty QuerySet result.
history = self.params.get("entries", None) == "deleted_only"
if history:
if self.params.get("entries", None) == "deleted_only":
return qs
return super().apply_select_related(qs)

Expand All @@ -319,7 +318,7 @@ def lookups(self, request, model_admin):

def queryset(self, request, queryset):
if self.value():
return queryset.model.history.filter(history_type='-').distinct()
return queryset.model.history.filter(history_type='-').latest_of_each()
return queryset


Expand All @@ -330,6 +329,4 @@ def get_changelist(self, request, **kwargs):
def get_list_filter(self, request):
# Doing it here will add it to every inherited class. Alternatively,
# add SimpleHistoryShowDeletedFilter to the list_filter and remove the below.
return [SimpleHistoryShowDeletedFilter] + [
f for f in super().get_list_filter(request)
]
return [SimpleHistoryShowDeletedFilter, *super().get_list_filter(request)]

0 comments on commit 9b9bd0a

Please sign in to comment.