问题
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