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 Jul 28, 2023
1 parent e5fc8d1 commit 0c116b1
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 @@ -317,7 +316,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 @@ -328,6 +327,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 0c116b1

Please sign in to comment.