From e044c700722c0a392da24581dac9ad4b7ec25ffb Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Sun, 4 Feb 2024 01:45:54 -0500 Subject: [PATCH] Fix inversion of next and last for scrobbles --- vrobbler/apps/scrobbles/models.py | 42 ++++++++++++++++++------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/vrobbler/apps/scrobbles/models.py b/vrobbler/apps/scrobbles/models.py index 44f350a..80c2979 100644 --- a/vrobbler/apps/scrobbles/models.py +++ b/vrobbler/apps/scrobbles/models.py @@ -575,28 +575,21 @@ class Scrobble(TimeStampedModel): is_stale = True return is_stale - @property - def previous(self) -> "Scrobble": - return ( - self.media_obj.scrobble_set.order_by("-timestamp") - .filter(timestamp__lt=self.timestamp) - .first() - ) - @property def next(self) -> "Scrobble": return ( - self.media_obj.scrobble_set.order_by("timestamp") - .filter(timestamp__gt=self.timestamp) + self.media_obj.scrobble_set.order_by("-timestamp") + .exclude(id=self.id) + .filter(timestamp__lt=self.timestamp) .first() ) @property - def previous_all(self) -> "Scrobble": + def previous(self) -> "Scrobble": return ( - Scrobble.objects.filter(media_type=self.media_type) - .order_by("-timestamp") - .filter(timestamp__lt=self.timestamp) + self.media_obj.scrobble_set.order_by("timestamp") + .exclude(id=self.id) + .filter(timestamp__gt=self.timestamp) .first() ) @@ -604,16 +597,19 @@ class Scrobble(TimeStampedModel): def next_all(self) -> "Scrobble": return ( Scrobble.objects.filter(media_type=self.media_type) + .exclude(id=self.id) .order_by("-timestamp") - .filter(timestamp__gt=self.timestamp) + .filter(timestamp__lt=self.timestamp) .first() ) @property - def previous_all_media(self) -> "Scrobble": + def previous_all(self) -> "Scrobble": return ( - Scrobble.objects.order_by("-timestamp") - .filter(timestamp__lt=self.timestamp) + Scrobble.objects.filter(media_type=self.media_type) + .exclude(id=self.id) + .order_by("-timestamp") + .filter(timestamp__gt=self.timestamp) .first() ) @@ -621,6 +617,16 @@ class Scrobble(TimeStampedModel): def next_all_media(self) -> "Scrobble": return ( Scrobble.objects.order_by("-timestamp") + .exclude(id=self.id) + .filter(timestamp__lt=self.timestamp) + .first() + ) + + @property + def previous_all_media(self) -> "Scrobble": + return ( + Scrobble.objects.order_by("-timestamp") + .exclude(id=self.id) .filter(timestamp__gt=self.timestamp) .first() )