Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 生成唯一编号序列以用作app engine数据存储的实体密钥_Python_Google App Engine_Google Cloud Datastore - Fatal编程技术网

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

Python 生成唯一编号序列以用作app engine数据存储的实体密钥,python,google-app-engine,google-cloud-datastore,Python,Google App Engine,Google Cloud Datastore,有没有人得到过创建一个唯一的数字序列作为Google app engine数据存储中实体的键的示例代码 希望使用顺序顺序号作为键。使用db。按说明分配\u id(),为实体生成唯一的ID 下面是从上面链接的示例中衍生出来的一个快速示例: from google.appengine.ext import db # get unique ID number - I just get 1 here, but you could get many ... new_ids = db.allocate_i

有没有人得到过创建一个唯一的数字序列作为Google app engine数据存储中实体的键的示例代码

希望使用顺序顺序号作为键。

使用
db。按说明分配\u id()
,为实体生成唯一的ID

下面是从上面链接的示例中衍生出来的一个快速示例:

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

()

您可能想看看在哪里可以找到序列号的实现。

或者干脆不指定一个键,让数据存储为您生成一个,这将产生完全相同的效果。@NickJohnson,这是从Google App Engine的1.8.1版本开始的。