做Key.from_路径点击数据存储?

2024-10-03 09:09:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个要批量获取的键名列表 (键名存储在附加到实体的StringListProperty中)。 我的总体计划是:

usernames = userrefInstance.users # A collection of strings on another 
model. 
keys = [Key.from_path('User', key_name) for username in usernames] 
users = db.get(keys)

我的问题是Key.from_路径点击数据存储?我试着做 尽快,如果Key.from_路径打到数据仓库我要工作了 另一种存储密钥集合的方法-我并不特别想这么做 将Key对象存储在list属性中,因为我还提供了user 跨StringListProperties的友好查询。在


Tags: keyfrom路径实体列表批量keysusers
2条回答

传递给Key.from_path()的参数包含构建唯一键所需的所有信息,因此不需要它命中数据存储。在

Each entity in the Datastore has a key that uniquely identifies it. The key consists of the following components:

  1. The kind of the entity, which categorizes it for the purpose of Datastore queries
  2. An identifier for the individual entity, which can be either
    • a key name string
    • an integer numeric ID
  3. An optional ancestor path locating the entity within the Datastore hierarchy

来源:https://developers.google.com/appengine/docs/python/datastore/entities

在对另一组人进行挖掘和提问后,发现:

keys are entirely determined by the app ID and the path, so there's no need to access the datastore for this. - Nick Johnson

或者您也可以使用数据库键在

相关问题 更多 >