Skip to content

Commit 2ccf550

Browse files
committed
Some simple tidying
.distinct() -> .latest_of_each() prevents multiple deletes from adding multiple rows for the same object.
1 parent 7bb7b4f commit 2ccf550

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
@@ -290,8 +290,7 @@ class SimpleHistoryChangeList(ChangeList):
290290
def apply_select_related(self, qs):
291291
# Our qs is different if we use the history, so the normal select_related
292292
# won't work and results in an empty QuerySet result.
293-
history = self.params.get("entries", None) == "deleted_only"
294-
if history:
293+
if self.params.get("entries", None) == "deleted_only":
295294
return qs
296295
return super().apply_select_related(qs)
297296

@@ -316,7 +315,7 @@ def lookups(self, request, model_admin):
316315

317316
def queryset(self, request, queryset):
318317
if self.value():
319-
return queryset.model.history.filter(history_type="-").distinct()
318+
return queryset.model.history.filter(history_type="-").latest_of_each()
320319
return queryset
321320

322321

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

0 commit comments

Comments
 (0)