From afcbe087bb7a38ea4d3970744f6a9a72822be034 Mon Sep 17 00:00:00 2001 From: Marwin Schulz Date: Fri, 20 Mar 2026 09:07:01 +0100 Subject: [PATCH] Replace 'recently refreshed' sort with 'most recent episode' in feed list Annotates feed queryset with Max(episodes__pub_date) so feeds are sorted by when their latest episode was published, not when the feed was last fetched. Co-Authored-By: Claude Sonnet 4.6 --- podcasts/views.py | 7 +++++-- static/js/app.js | 2 +- templates/radio/player.html | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/podcasts/views.py b/podcasts/views.py index 08b14ae..e7ecc10 100644 --- a/podcasts/views.py +++ b/podcasts/views.py @@ -5,7 +5,7 @@ import xml.etree.ElementTree as ET import feedparser import requests from django.conf import settings -from django.db.models import Count, F, Q +from django.db.models import Count, F, Max, Q from django.http import JsonResponse from django.utils import timezone from django.views.decorators.csrf import csrf_exempt @@ -176,7 +176,8 @@ def feed_list(request): feeds = list( request.user.podcast_feeds - .values('id', 'title', 'artwork_url', 'rss_url', 'last_refreshed_at', 'author', 'added_at', 'auto_queue') + .annotate(latest_episode_at=Max('episodes__pub_date')) + .values('id', 'title', 'artwork_url', 'rss_url', 'last_refreshed_at', 'author', 'added_at', 'auto_queue', 'latest_episode_at') ) for f in feeds: @@ -184,6 +185,8 @@ def feed_list(request): f['last_refreshed_at'] = f['last_refreshed_at'].isoformat() if f['added_at']: f['added_at'] = f['added_at'].isoformat() + if f['latest_episode_at']: + f['latest_episode_at'] = f['latest_episode_at'].isoformat() return JsonResponse({'feeds': feeds}) diff --git a/static/js/app.js b/static/js/app.js index 8e0c96e..b06d67c 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -1193,7 +1193,7 @@ function sortFeeds(order) { if (order === 'alpha') podcastFeeds.sort((a, b) => a.title.localeCompare(b.title)); if (order === 'alpha-desc') podcastFeeds.sort((a, b) => b.title.localeCompare(a.title)); if (order === 'added') podcastFeeds.sort((a, b) => (b.added_at || '').localeCompare(a.added_at || '')); - if (order === 'refreshed') podcastFeeds.sort((a, b) => (b.last_refreshed_at || '').localeCompare(a.last_refreshed_at || '')); + if (order === 'latest_episode') podcastFeeds.sort((a, b) => (b.latest_episode_at || '').localeCompare(a.latest_episode_at || '')); renderFeedList(); } diff --git a/templates/radio/player.html b/templates/radio/player.html index ccab3e7..d41e6eb 100644 --- a/templates/radio/player.html +++ b/templates/radio/player.html @@ -256,7 +256,7 @@ - +