Appengine - 可能获得一个实体只使用关键字符串没有模型名称? [英] Appengine - Possible to get an entity using only key string without model name?

查看:123
本文介绍了Appengine - 可能获得一个实体只使用关键字符串没有模型名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够拥有一个能够处理多种不同类型对象的视图。

所有视图都将获得的关键字符串例如:

/ p>

agpwb2xsdGhyZWFkchULEg9wb2xsY29yZV9hbnN3ZXIYAww



不知道模型类型,是否可以从该密钥字符串中检索实体?



谢谢

解决方案

不需要超类,只需使用db.get ):

  from google.appengine.ext import db 
key_str ='agpwb2xsdGhyZWFkchULEg9wb2xsY29yZV9hbnN3ZXIYAww'
entity = db .get(key_str)


I want to be able to have a view that will act upon a number of different types of objects

all the view will get is the key string eg:

agpwb2xsdGhyZWFkchULEg9wb2xsY29yZV9hbnN3ZXIYAww

without knowing the model type, is it possible to retrieve the entity from just that key string?

thanks

解决方案

No superclassing required, just use db.get():

from google.appengine.ext import db
key_str = 'agpwb2xsdGhyZWFkchULEg9wb2xsY29yZV9hbnN3ZXIYAww'
entity = db.get(key_str)

这篇关于Appengine - 可能获得一个实体只使用关键字符串没有模型名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆