Is it possible to get an entity using only a key string without a model name?

I want to have a representation that will act on several different types of objects

all views will receive a key string, for example:

agpwb2xsdGhyZWFkchULEg9wb2xsY29yZV9hbnN3ZXIYAww

Without knowing the type of model, is it possible to get an object only from this line?

thanks

+3
source share
2 answers

Superclassification is not required, just use db.get ():

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

If you design your models so that they all use the usual superclass, you could get your objects using something like:

entity = CommonSuperclass.get('agpwb2xsdGhyZWFkchULEg9wb2xsY29yZV9hbnN3ZXIYAww')
+1
source

Source: https://habr.com/ru/post/1706877/


All Articles