Django Q,icontains不工作

时间:2015-04-25 13:19:55

标签: python django sqlite django-q

我有以下用于搜索我的博客的简单代码:

             * @classdesc Used for adding dropdown functionality to &lt;select&gt;&lt;/select&gt; elements ONLY.<br/>
             * For dropdowns that are not select elements (i.e. divs or uls), the {@link ui/dropdown} should be used instead.
             * @author Mark Kennedy <mdkennedy@gannett.com>
             * @constructs form/dropdown

当查询为def SearchView(request): template_name = 'search_results.html' q = request.GET.get('q', None) if q is 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() for 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) 时,我会收到包含Bangkok的帖子。但是如果查询是Bangkok,则不返回任何内容。在django文档中,它说bangkok应该忽略大小写,但它对我不起作用。

我使用SQlite,我真的需要它作为我的数据库引擎。

有什么想法吗?我将不胜感激!

0 个答案:

没有答案