Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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


2 Answers

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

from google.appengine.ext import db
key_str = 'agpwb2xsdGhyZWFkchULEg9wb2xsY29yZV9hbnN3ZXIYAww'
entity = db.get(key_str)
like image 174
jamtoday Avatar answered Apr 18 '26 19:04

jamtoday


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')
like image 30
B.E. Avatar answered Apr 18 '26 20:04

B.E.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!