Attempt to filter blogs by category
This commit is contained in:
parent
b218ee1662
commit
ee35fbd784
1 changed files with 13 additions and 1 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue