From b42611f38c2e963c35629383747a4ec3a89837d6 Mon Sep 17 00:00:00 2001 From: Felix Stupp Date: Sun, 7 Nov 2021 02:02:31 +0100 Subject: [PATCH] MediaCollection.next_episode: Moved operation into orm/db --- server/entertainment_decider/models.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/server/entertainment_decider/models.py b/server/entertainment_decider/models.py index 00128b6..c255c71 100644 --- a/server/entertainment_decider/models.py +++ b/server/entertainment_decider/models.py @@ -512,12 +512,10 @@ class MediaCollection(db.Entity, Tagable): @property def next_episode(self) -> Optional[MediaCollectionLink]: - #return orm \ - # .select(link for link in self.media_links if not link.element.watched) \ - # .order_by(*MediaCollectionLink.natural_order) \ - # .first() - episodes = MediaCollectionLink.sorted(self.__to_watch_episodes()) - return episodes[0] if len(episodes) > 0 else None + return orm \ + .select(link for link in self.media_links if not link.element.skip_over) \ + .order_by(MediaCollectionLink.sort_key) \ + .first() @property def completed(self) -> bool: