class ArticleSearchView(ListView): def get(self, request, *args, **kwargs): self.form = ArticleSearchForm(request.GET or None) return super(ArticleSearchView, self).get(self, request, *args, **kwargs) def get_queryset(self): articles = [] if self.form.is_valid(): keywords = self.form.cleaned_data['q'] articles = Article.objects.get_active() articles = articles.filter( Q(title__icontains=keywords) | Q(text__icontains=keywords) | Q(excerpt__icontains=keywords) | Q(tags__name__in=[keywords])).distinct() return articles def get_context_data(self, **kwargs): context = super(ArticleSearchView, self).get_context_data(**kwargs) context['query'] = self.form.cleaned_data['q'] context['article_search_form'] = self.form return context
def render(self, context): context[self.var_name] = ArticleSearchForm() return ''
def get_context_data(self, **kwargs): context = super(ArticleListView, self).get_context_data(**kwargs) context['article_search_form'] = ArticleSearchForm() return context
def get(self, request, *args, **kwargs): self.form = ArticleSearchForm(request.GET or None) return super(ArticleSearchView, self).get(self, request, *args, **kwargs)