views:

222

answers:

2

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

A: 

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')
Benedikt Eger
+3  A: 

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

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