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 7bb7b4f commit 2ccf550
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 @@ -290,8 +290,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)

Check warning on line 295 in simple_history/admin.py

View check run for this annotation

Codecov / codecov/patch

simple_history/admin.py#L294-L295

Added lines #L294 - L295 were not covered by tests

Expand All @@ -316,7 +315,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

Check warning on line 319 in simple_history/admin.py

View check run for this annotation

Codecov / codecov/patch

simple_history/admin.py#L318-L319

Added lines #L318 - L319 were not covered by tests


Expand All @@ -327,6 +326,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)]

Check warning on line 329 in simple_history/admin.py

View check run for this annotation

Codecov / codecov/patch

simple_history/admin.py#L329

Added line #L329 was not covered by tests

0 comments on commit 2ccf550

Please sign in to comment.