Skip to content

Commit 0c116b1

Browse files
committed
Some simple tidying
.distinct() -> .latest_of_each() prevents multiple deletes from adding multiple rows for the same object.
1 parent e5fc8d1 commit 0c116b1

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

@@ -317,7 +316,7 @@ def lookups(self, request, model_admin):
317316

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

323322

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

0 commit comments

Comments
 (0)