简体   繁体   English

Django QuerySet中的icontains不给出不区分大小写的结果?

[英]icontains in Django QuerySet doesn't give the case insensitive result?

I am using Django1.6, I am trying to use QuerySet filter, but it is behaving strangely. 我正在使用Django1.6,我正在尝试使用QuerySet过滤器,但它表现得很奇怪。

Here is my code: 这是我的代码:

test_listing = Test.objects.filter(site__id=_site_id, show_on_site=True)

Then I am trying to get the listing based on the searched text: 然后我试图根据搜索到的文本获取列表:

test_listing = test_listing.filter(name__icontains = searched_text)

I am using MySQL as database for my project. 我使用MySQL作为我的项目的数据库。

When I search for 'foo' it returns a blank list, but when I search for 'FOO', it returns the list of objects where there is an entry of FOOBAR as a name in my Test table. 当我搜索'foo'时它会返回一个空白列表,但是当我搜索'FOO'时,它会返回在我的Test表中有一个FOOBAR条目作为名称的对象列表。

Why is it behaving so strangely...? 为什么它表现得那么奇怪......?

this is perhaps due to the mysql-db which you are using, may be your db table (name) column have the sql case-sensitive coollate 这可能是由于你正在使用的mysql-db ,可能是你的db表(name)列有sql区分大小写的coollat​​e

ALTER TABLE t1 MODIFY
    col1 VARCHAR(5)
      CHARACTER SET latin1
      COLLATE latin1_swedish_ci;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Django queryset.query和在mysql控制台中运行的查询没有给出相同的结果 - Django queryset.query and query run in mysql console doesn't give the same result 如何使用不区分大小写的 __in 过滤 django 查询集? - How to filter a django queryset using case insensitive __in? Django:icontains大小写对Unicode敏感 - Django: icontains case is sensitive for unicode Django Queryset icontains()方法没有返回完全匹配 - Django Queryset icontains() method not returning exact match Python contains 和 icontains 都返回不区分大小写的结果 - Python contains and icontains both return case insensitive results Django QuerySet.union()-或QuerySet.raw()实现不区分大小写的Mutli-Search - Django QuerySet.union() -or- QuerySet.raw() to Achieve Case-Insensitive Mutli-Search 为什么用icontains过滤django区分大小写? - Why filtering django with icontains is case sensitive? 在Django中,values(* field)不会提供带有切片查询集的ForeignKey字段的所有值 - In django, values(*field) doesn't give all values of ForeignKey field with sliced queryset 如何在Django queryset中的DictField的键值中使用icontains? - How to use icontains in a key value of a DictField in Django queryset? 简单的Django queryset __icontains搜索将首先找到大多数特定元素 - Simple Django queryset __icontains search that will find most specific elements first
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM