Attempt to filter blogs by category

This commit is contained in:
PCoder 2018-04-17 11:49:01 +02:00
parent b218ee1662
commit ee35fbd784

View file

@ -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