From 46565f520c310c7cae4c7f2d0f7dcafb143e3374 Mon Sep 17 00:00:00 2001 From: Kumi Date: Fri, 6 May 2022 09:37:10 +0200 Subject: [PATCH] Fix playlist template tag --- frontend/templatetags/playlists.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/frontend/templatetags/playlists.py b/frontend/templatetags/playlists.py index bede324..61d6742 100644 --- a/frontend/templatetags/playlists.py +++ b/frontend/templatetags/playlists.py @@ -7,14 +7,17 @@ from backend.models import Playlist register = template.Library() + @register.simple_tag def other_videos(playlist, video, count=4): videos = playlist.videos.all().order_by("-published") - older = list(videos.filter(published__lt=video.published)) - newer = list(videos.filter(published__gt=video.published)) + older = sorted( + list(videos.filter(published__lt=video.published)), key=lambda x: x.published) + newer = sorted( + list(videos.filter(published__gt=video.published)), key=lambda x: x.published) - newer_out = newer[:count] - older_out = older[-count-len(newer_out):] + newer_out = newer[:count-1] + older_out = older[-count+len(newer_out):] - return sorted(older_out + newer_out, key=lambda x: x.published) \ No newline at end of file + return sorted(older_out + newer_out, key=lambda x: x.published)