NDB查询以字符串开头的结果 [英] NDB querying results that start with a string
本文介绍了NDB查询以字符串开头的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Google App Engine的NDB,我正在查询以用户输入的字符串开头的所有项目。
示例:
abc_123
abcdefg
123abc
查询abc应返回abc_123,abcdefg(但不是123abc,因为它不包含
,以abc开头)
我以前使用下面的代码来达到类似但不同的目的:
q = q.filter(order._properties [kw] .IN(values_list))
其中过滤所有values_list中的值为kw的值,现在我正在过滤所有以kw字符串开头的值。
Kind.query(ndb.AND(Kind.property> =abc,Kind .property< =abcz))
Working with Google App Engine's NDB, I'm looking to query for all items that start with a user-inputted string. Example:
abc_123
abcdefg
123abc
Querying for "abc" should return abc_123, abcdefg (however, not 123abc as it doesn't start with "abc")
I previously used the code below for a similar but different purpose:
q = q.filter(order._properties[kw].IN(values_list))
which filtered for all values in values_list that were in kw, I am now looking to filter for all values that start with a string that are in kw.
解决方案
Try:
Kind.query(ndb.AND(Kind.property >= "abc", Kind.property <= "abcz"))
这篇关于NDB查询以字符串开头的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文