Código Python:
Ver original
class EntrySearch(ListView): model = Entry paginate_by = 15 template_name = "blog/entry_search.html" def get_queryset(self): qset = super(EntrySearch, self).get_queryset() new_data = self.request.GET.copy() self.form = EntrySearchForm(new_data) if self.form.is_valid(): stop_words_list = re.compile(STOP_WORDS, re.IGNORECASE) search_term = self.form.cleaned_data['q'] cleaned_search_term = stop_words_list.sub('', search_term) terms = [term.strip() for term in cleaned_search_term.split()] if terms: q_objects = [] for term in terms: q_objects.append(Q(title__icontains=term)) q_objects.append(Q(field2__icontains=term)) q_objects.append(Q(field3__name__icontains=term)) q_objects.append(Q(field4__name__icontains=term)) q_objects.append(Q(field5__name__icontains=term)) qset = qset.filter(reduce(operator.or_,q_objects)).distinct() else: qset = [] else: form = EntrySearchForm() return qset
Que opinan que mejoras se podrían implementar.
Gracias.