Fix inversion of next and last for scrobbles

This commit is contained in:
2024-02-04 01:45:54 -05:00
parent d3e09c25bd
commit e044c70072

View File

@ -575,28 +575,21 @@ class Scrobble(TimeStampedModel):
is_stale = True is_stale = True
return is_stale return is_stale
@property
def previous(self) -> "Scrobble":
return (
self.media_obj.scrobble_set.order_by("-timestamp")
.filter(timestamp__lt=self.timestamp)
.first()
)
@property @property
def next(self) -> "Scrobble": def next(self) -> "Scrobble":
return ( return (
self.media_obj.scrobble_set.order_by("timestamp") self.media_obj.scrobble_set.order_by("-timestamp")
.filter(timestamp__gt=self.timestamp) .exclude(id=self.id)
.filter(timestamp__lt=self.timestamp)
.first() .first()
) )
@property @property
def previous_all(self) -> "Scrobble": def previous(self) -> "Scrobble":
return ( return (
Scrobble.objects.filter(media_type=self.media_type) self.media_obj.scrobble_set.order_by("timestamp")
.order_by("-timestamp") .exclude(id=self.id)
.filter(timestamp__lt=self.timestamp) .filter(timestamp__gt=self.timestamp)
.first() .first()
) )
@ -604,16 +597,19 @@ class Scrobble(TimeStampedModel):
def next_all(self) -> "Scrobble": def next_all(self) -> "Scrobble":
return ( return (
Scrobble.objects.filter(media_type=self.media_type) Scrobble.objects.filter(media_type=self.media_type)
.exclude(id=self.id)
.order_by("-timestamp") .order_by("-timestamp")
.filter(timestamp__gt=self.timestamp) .filter(timestamp__lt=self.timestamp)
.first() .first()
) )
@property @property
def previous_all_media(self) -> "Scrobble": def previous_all(self) -> "Scrobble":
return ( return (
Scrobble.objects.order_by("-timestamp") Scrobble.objects.filter(media_type=self.media_type)
.filter(timestamp__lt=self.timestamp) .exclude(id=self.id)
.order_by("-timestamp")
.filter(timestamp__gt=self.timestamp)
.first() .first()
) )
@ -621,6 +617,16 @@ class Scrobble(TimeStampedModel):
def next_all_media(self) -> "Scrobble": def next_all_media(self) -> "Scrobble":
return ( return (
Scrobble.objects.order_by("-timestamp") 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) .filter(timestamp__gt=self.timestamp)
.first() .first()
) )