应用程序引擎bulkloader post_import_function - 如何调用实体上的方法
尝试使用 python GeoModel 类和bulkloader。我正在调用以下 post_import_function
,它工作正常,并且实体已使用正确设置的位置字段进行更新。
def post_process_obj(input_dict, entity_instance, bulkload_state):
entity_instance['location'] = db.GeoPt(entity_instance['latitude'], entity_instance['longitude'])
return entity_instance
但我需要做的是在保存到数据存储之前对实体调用 entity_instance.update_location()
。虽然 entity_instance
是一个实体,而不是 GeoModel 的子类,所以我不清楚如何做到这一点。不久前有一篇文章说内联代码或调用函数并将实体传递给它,但我不知道这是什么意思。
感谢您的任何帮助/示例代码。
Trying to use python GeoModel class and the bulkloader. I'm calling the following post_import_function
which works fine and the entity is updated with the location field set properly.
def post_process_obj(input_dict, entity_instance, bulkload_state):
entity_instance['location'] = db.GeoPt(entity_instance['latitude'], entity_instance['longitude'])
return entity_instance
But what I need to do is call entity_instance.update_location()
on the entity before it saves to the data store. The entity_instance
though is an Entity, not a subclass of GeoModel so I'm not clear how to do this. There was a post a while back that said inline the code or call a function and pass the entity to it but I don't know what that was supposed to mean.
Thanks for any help/sample code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能这样做 - 正如您所观察到的,您正在处理一个
Entity
,而不是模型的实例。唯一的选择是获取您想要执行的代码,复制并粘贴它,然后修改它以与实体一起使用。You can't do this - as you observed, you're dealing with an
Entity
, not an instance of your model. The only option is to take the code that you want to execute it, copy-and-paste it, and modify it to work with an entity instead.