How to search structured properties ? google app engine

爱⌒轻易说出口 提交于 2019-12-24 13:03:12

问题


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

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

for example I have city entity:

categories_unhidden_list = []
for category in city.categories :
    if not category.hidden :
        categories_unhidden_list.append(category)

but I would like to get the categories_unhidden_list from the datastore !


回答1:


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.

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.



来源:https://stackoverflow.com/questions/27105509/how-to-search-structured-properties-google-app-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!