Appengine - Possible to get an entity using only key string without model name?

你离开我真会死。 提交于 2020-02-01 05:46:27

问题


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


回答1:


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

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



回答2:


If you design your models so they all use a common superclass it should be possible to retrieve your objects by using something like:

entity = CommonSuperclass.get('agpwb2xsdGhyZWFkchULEg9wb2xsY29yZV9hbnN3ZXIYAww')


来源:https://stackoverflow.com/questions/776324/appengine-possible-to-get-an-entity-using-only-key-string-without-model-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!