python - Django Q, icontains not working -
i've following simple code searching blog:
def searchview(request): template_name = 'search_results.html' q = request.get.get('q', none) if q none or q == '': return redirect('/') object_list = [] query = (q(title__istartswith=q) | q(title__icontains=q) | q(content__istartswith=q) | q(content__icontains=q)) models = contenttype.objects.filter( model__in=settings.searchable_objects).all() model in models: obj = model.get_all_objects_for_this_type().filter(query).all() object_list = chain(object_list, obj) objects = list(object_list) context = {'posts': objects, 'q': q} template = template_name return render(request, template, context)
and when query bangkok
, posts containing bangkok
. if query bangkok
, nothing returned. in django documentation, says icontains
should ignore case, doesn't work me.
i use sqlite, , need db engine.
any ideas? grateful!
Comments
Post a Comment