From ee35fbd7849f5d2d1ea49773038024928ba84351 Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 17 Apr 2018 11:49:01 +0200 Subject: [PATCH] Attempt to filter blogs by category --- ungleich/views.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ungleich/views.py b/ungleich/views.py index 3610d1bc..36583a04 100644 --- a/ungleich/views.py +++ b/ungleich/views.py @@ -7,6 +7,7 @@ from djangocms_blog.models import Post from djangocms_blog.views import PostListView from djangocms_blog.settings import get_setting from django.utils.translation import ugettext_lazy as _ +from djangocms_blog.models import BlogCategory def blog(request): @@ -20,6 +21,7 @@ def blog(request): class PostListViewUngleich(PostListView): + tags = None model = Post context_object_name = 'post_list' base_template_name = 'post_list_ungleich.html' @@ -38,7 +40,17 @@ class PostListViewUngleich(PostListView): def get_queryset(self): language = get_language() - queryset = self.model.objects.filter(publish=True).translated(language) + if self.tags: + queryset = (self.model + .objects + .filter(tags__name__in=[self.tags], publish=True) + .translated(language)) + else: + queryset = (self.model + .objects + .filter(publish=True) + .translated(language) + ) setattr(self.request, get_setting('CURRENT_NAMESPACE'), self.config) return queryset