如何搜索结构化属性?谷歌应用引擎 [英] How to search structured properties ? google app engine

查看:207
本文介绍了如何搜索结构化属性?谷歌应用引擎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个模型类别和城市:

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)

但我想从数据存储区获取categories_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 ,而不是在他们重复列表中查询Y的位置 key_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屋!

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