NDB 查询以字符串开头的结果 [英] NDB querying results that start with a string

查看:27
本文介绍了NDB 查询以字符串开头的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Google App Engine 的 NDB,我希望查询以用户输入的字符串开头的所有项目.示例:

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

查询 "abc" 应该返回 abc_123, abcdefg(但是,不是 123abc,因为它没有以abc"开头)

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))

过滤了 values_list 中以 kw 为单位的所有值,我现在正在寻找以 kw 为单位的字符串开头的所有值.

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.

推荐答案

尝试:

Kind.query(ndb.AND(Kind.property >= "abc", Kind.property <= "abcz"))

这篇关于NDB 查询以字符串开头的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆