Fix playlist template tag
This commit is contained in:
parent
905e5c2b5e
commit
46565f520c
1 changed files with 8 additions and 5 deletions
|
@ -7,14 +7,17 @@ from backend.models import Playlist
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def other_videos(playlist, video, count=4):
|
def other_videos(playlist, video, count=4):
|
||||||
videos = playlist.videos.all().order_by("-published")
|
videos = playlist.videos.all().order_by("-published")
|
||||||
|
|
||||||
older = list(videos.filter(published__lt=video.published))
|
older = sorted(
|
||||||
newer = list(videos.filter(published__gt=video.published))
|
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]
|
newer_out = newer[:count-1]
|
||||||
older_out = older[-count-len(newer_out):]
|
older_out = older[-count+len(newer_out):]
|
||||||
|
|
||||||
return sorted(older_out + newer_out, key=lambda x: x.published)
|
return sorted(older_out + newer_out, key=lambda x: x.published)
|
Loading…
Reference in a new issue