From 3f5e2e80c6c888acb20155ebf82301ed01e92c0e Mon Sep 17 00:00:00 2001 From: Yaroslsav-95 Date: Thu, 4 Oct 2018 03:08:47 +0300 Subject: fix unpublished post appearing on rss feed --- weblog/feeds.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'weblog/feeds.py') diff --git a/weblog/feeds.py b/weblog/feeds.py index 59fcd8f..bb5c65c 100644 --- a/weblog/feeds.py +++ b/weblog/feeds.py @@ -5,6 +5,7 @@ from weblog.models import BlogPost, Translation, Category, CategoryTranslation from weblog.apps import SETTINGS as blog_settings from django.utils.translation import ugettext_lazy as _, pgettext_lazy from django.utils import translation +import datetime class BlogFeed(Feed): @@ -43,9 +44,10 @@ class BlogFeed(Feed): return _('Latest blog posts on %(blog_title)s') % {'blog_title': blog_settings['blog_title']} def items(self, obj): + now = datetime.datetime.now() if obj: - return BlogPost.objects.filter(category__slug=obj).order_by('-publish_date')[:blog_settings['posts_per_page']] - return BlogPost.objects.order_by('-publish_date')[:blog_settings['posts_per_page']] + return BlogPost.objects.filter(category__slug=obj, published=True, publish_date__lte=now).order_by('-publish_date')[:blog_settings['posts_per_page']] + return BlogPost.objects.order_by('-publish_date').filter(published=True, publish_date__lte=now)[:blog_settings['posts_per_page']] def item_title(self, item): translation_exists = False -- cgit v1.2.3