python Django 查询过滤器中的参数“name__icontains”和“description__icontains”是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2571149/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What do the arguments "name__icontains" and "description__icontains" mean in a Django query filter?
提问by zjm1126
maps = (maps.filter(name__icontains=search_terms) |
maps.filter(description__icontains=search_terms))
I can't find the meaning of these filter arguments.
我找不到这些过滤器参数的含义。
回答by Garethr
It's a case-insensitive containment test.
这是一个不区分大小写的包容性测试。
Example:
例子:
Entry.objects.get(headline__icontains='Lennon')
SQL equivalent:
SQL 等效项:
SELECT ... WHERE headline ILIKE '%Lennon%';
In your case the code says maps should be True
if either the name or the description field contains the value of search_terms
.
在您的情况下,True
如果名称或描述字段包含search_terms
.
回答by vicvicvic
xxx_icontains
searches the whole xxx
field for the argument, case-insensitively.
xxx_icontains
在整个xxx
字段中搜索参数,不区分大小写。
http://docs.djangoproject.com/en/1.1/ref/models/querysets/#icontains
http://docs.djangoproject.com/en/1.1/ref/models/querysets/#icontains