如何搜索结构化属性?谷歌应用引擎 [英] How to search structured properties ? google app engine
问题描述
我有两个模型类别和城市:
I have two models categories and cities:
class category(ndb.Model):
hidden = ndb.BooleanProperty()
categoryName = ndb.StringProperty()
class city(ndb.Model):
categories = ndb.StructuredProperty(category,repeated = True)
cityName = ndb.StringProperty()
我有 cityEntity:如何返回仅包含 category.hidden = false 的类别列表?
I have cityEntity: How to return categories list that contain just category.hidden = false ?
可以获取类别列表,然后遍历类别列表并仅提取未隐藏的类别
edit: it's possible to get the categories list, then Loop through the categories list and extract just the categories which not hidden
例如我有城市实体:
categories_unhidden_list = []
for category in city.categories :
if not category.hidden :
categories_unhidden_list.append(category)
但我想从数据存储中获取 category_unhidden_list !
but I would like to get the categories_unhidden_list from the datastore !
推荐答案
查询将只匹配被查询的内容.如果实体满足条件,它将返回实体.如果您有重复的属性并且查询匹配其中一个值,它将返回实体中的整个列表,而不仅仅是匹配的列表.这就是为什么重复的属性应该几乎总是一个键、一个简单的值或一个简单的键值对.
A query will match only what is queried for. If the entity fulfills the condition, it will return the entity. If you have a repeated property and a query matches one of the values, it will return the whole list in the entity, not only the one that matches. This is why repeated properties should almost always be either a key, a simple value, or a simple key value pair.
您可能需要查看 A) 投影查询 和 B) 构建您的数据,以便您可以查询具有 x
值和 key_y
父实体的类别,而不是在它们具有 的地方查询 Ykey_x
在他们的重复列表中.
You may want to look into A) projection queries and B) structuring your data so that you can query for categories that have a value of x
and a parent-entity of key_y
, instead of querying for Y's where they have key_x
in their repeated list.
这篇关于如何搜索结构化属性?谷歌应用引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!