Modify PostListViewUngleich: Filter posts by category if specified
This commit is contained in:
		
					parent
					
						
							
								ff1d4f1a6f
							
						
					
				
			
			
				commit
				
					
						7d211b3333
					
				
			
		
					 1 changed files with 13 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue