# HG changeset patch # User neko259 # Date 2017-01-30 16:58:42 # Node ID d9dcb07b1aa35433f09a9c21c218c9f8ff427020 # Parent 6a5309f4272725b74961713fc5eb399663034e4c Search posts by text and title diff --git a/boards/views/search.py b/boards/views/search.py --- a/boards/views/search.py +++ b/boards/views/search.py @@ -1,5 +1,6 @@ from django.shortcuts import render from django.views.generic import View +from django.db.models import Q from boards.abstracts.paginator import get_paginator from boards.forms import SearchForm, PlainErrorList @@ -32,8 +33,8 @@ class BoardSearchView(View): if form.is_valid(): query = form.cleaned_data[FORM_QUERY] if len(query) >= MIN_QUERY_LENGTH: - results = Post.objects.filter(text__icontains=query)\ - .order_by('-id') + results = Post.objects.filter(Q(text__icontains=query) | + Q(title__icontains=query)).order_by('-id') paginator = get_paginator(results, RESULTS_PER_PAGE) page = int(request.GET.get(REQUEST_PAGE, '1'))