简体   繁体   English

生成唯一编号序列,以用作app引擎数据存储的实体密钥

[英]Generating unique number sequence for use as entity key for app engine datastore

Has anyone got any example code for creating a unique number sequence to be used as keys for an entity in a Google app engine datastore? 有没有人有任何示例代码用于创建唯一的数字序列,以用作Google应用引擎数据存储区中的实体的键?

Would like to use sequential order numbers as the key. 想使用顺序订单号作为关键。

Use db.allocate_ids() as described here to generate unique IDs for your entities. 使用此处所述的db.allocate_ids()为您的实体生成唯一ID。

Here's a quick example derived from the example at the above link: 以下是从上述链接示例中获得的快速示例:

from google.appengine.ext import db

# get unique ID number - I just get 1 here, but you could get many ...
new_ids = db.allocate_ids(handmade_key, 1)

# db.allocate_ids() may return longs but db.Key.from_path requires an int (issue 2970)
new_id_num = int(new_id[0])

# assign the new ID to an entity
new_key = db.Key.from_path('MyModel', new_id_num)
new_instance = MyModel(key=new_key)
...
new_instance.put()

( issue 2970 reference ) 问题2970参考

您可能想看看如何在Google AppEngine上实现“自动增量” ,您可以在其中找到序列号的实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 应用引擎数据存储实体的自定义键 - Custom key for app-engine datastore entity 从Google App Engine数据存储区中的密钥获取实体属性 - Getting entity properties from Key in google app engine datastore 创建App Engine数据存储区实体 - Creating a App Engine Datastore entity 使用python应用程序引擎将电子邮件地址用作数据存储区密钥 - use email address as datastore key using python app engine 如何在没有在Google App Engine中读取数据存储的情况下从实体实例获取引用的实体属性的键名? - How to get to the key name of a referenced entity property from an entity instance without a datastore read in google app engine? 通过没有冲突的数字ID创建唯一的App Engine数据存储区实体-python - Creating unique app engine datastore entity by numeric ID without conflicts - python google app引擎数据存储区唯一ID - google app engine datastore unique id Google App Engine数据存储区中的实体组 - Entity groups in Google App Engine Datastore Google App Engine使用mapreduce对具有特定键的数据存储区实体执行操作 - Google App Engine Using mapreduce perform operation on entity of a datastore with specific key Python Google App Engine:如何在数据存储区中找到特定实体的计数? - Python Google App Engine: How do you find the count number of a particular entity in the datastore?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM