Skip to content

Commit 9b9bd0a

Browse files
committed
Some simple tidying
.distinct() -> .latest_of_each() prevents multiple deletes from adding multiple rows for the same object.
1 parent 95cebf5 commit 9b9bd0a

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

simple_history/admin.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,7 @@ class SimpleHistoryChangeList(ChangeList):
291291
def apply_select_related(self, qs):
292292
# Our qs is different if we use the history, so the normal select_related
293293
# won't work and results in an empty QuerySet result.
294-
history = self.params.get("entries", None) == "deleted_only"
295-
if history:
294+
if self.params.get("entries", None) == "deleted_only":
296295
return qs
297296
return super().apply_select_related(qs)
298297

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

320319
def queryset(self, request, queryset):
321320
if self.value():
322-
return queryset.model.history.filter(history_type='-').distinct()
321+
return queryset.model.history.filter(history_type='-').latest_of_each()
323322
return queryset
324323

325324

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

0 commit comments

Comments
 (0)