简体   繁体   English

在Google App Engine中,如何创建具有特定ID的模型?

[英]In Google App Engine, how do I create a model with a specific ID?

I have backed up all of the entities for a model in a CSV file. 我已经为CSV文件中的模型备份了所有实体。 I am recovering the entities to my local dev_server and would like to recreate the entities with an ID in the csv file (similar to how bulkloader does). 我正在将实体恢复到我的本地dev_server,并希望在csv文件中重新创建具有ID的实体(类似于bulkloader的工作方式)。 How do I pass in the desired ID for my new entity in my create statement? 如何在我的create语句中为新实体传入所需的ID?

playerID = 1234
player = Player(created = datetime.datetime(2012, 1, 25, 9, 20, 5, 757227), 
                nickname = u'chris', 
                email = u'chris@home.com')
player.put()

What do I add to Player() to create the player with player.key().id()==1234 when I call put()? 当我调用put()时,我添加到Player()以使用player.key()创建播放器.id()== 1234?

First you need to allocate the id range using allocate_id_range , to make sure to reserve the ids for those entities. 首先,您需要使用allocate_id_range分配id范围,以确保为这些实体保留ID。

And then just build the key manually, and pass it to Player constructor: 然后手动构建密钥,并将其传递给Player构造函数:

k = Key.from_path('Player', playerID)
player = Player(key = k, ...)
player.put()

暂无
暂无

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

相关问题 如何在Google App Engine中为模型定义唯一属性? - How do I define a unique property for a Model in Google App Engine? 如何在Google App Engine Python中创建同意屏幕 - How do I create a consent screen in Google App Engine Python 如何在Google App Engine上的python中创建唯一属性? - How do I create a unique property in python on google app engine? 在python Google App Engine 中,如何将模型的所有实体导出到Google Storage 中的文件中以供开发人员使用? - In the python Google App Engine, how do I export all the entities of a model to a file in Google Storage for developers? 如何在Google App Engine上查找特定于单个MapReduce作业的日志? - How do I find logs specific to a single MapReduce job on Google App Engine? 如何在 Google App Engine 上使用 Django 创建自定义 gunicorn 设置? - How do I create a custom gunicorn setup with Django on Google App Engine? 如何从Google App Engine应用程序解析XML? - How do I parse XML from a Google App Engine app? 如何将本地Google App Engine Python数据存储区复制到本地Google App Engine Java数据存储区? - How do I copy local Google App Engine Python datastore to local Google App Engine Java datastore? 我怎么能在谷歌应用程序引擎上为html5创建一个websocket - how can i create a websocket on google app engine for html5 Google App Engine模型类是如何存储的? - How are Google App Engine model classes stored?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM