From 7d211b33333ebca6e559f2c46f7bd2dc220dc309 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Tue, 17 Apr 2018 16:17:25 +0200 Subject: [PATCH] Modify PostListViewUngleich: Filter posts by category if specified --- ungleich/views.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ungleich/views.py b/ungleich/views.py index 36583a04..c1d7445d 100644 --- a/ungleich/views.py +++ b/ungleich/views.py @@ -21,7 +21,7 @@ def blog(request): class PostListViewUngleich(PostListView): - tags = None + category = None model = Post context_object_name = 'post_list' base_template_name = 'post_list_ungleich.html' @@ -40,10 +40,20 @@ class PostListViewUngleich(PostListView): def get_queryset(self): language = get_language() - if self.tags: + if self.category: + blog_category = ( + BlogCategory + ._default_manager + .language(language) + .filter( + translations__language_code=language, + translations__slug=self.category + ) + ) + queryset = (self.model .objects - .filter(tags__name__in=[self.tags], publish=True) + .filter(categories=blog_category, publish=True) .translated(language)) else: queryset = (self.model