python - GAE NDB Expando Model with dynamic Kind -


is possible assign dynamic entity kind expando model? example, want use model many types of dynamic entities:

class dynamic(ndb.expando):     """     handles "post types", such pages, posts, users, products, etc...     """     col = ndb.stringproperty()     parent = ndb.integerproperty()     name = ndb.stringproperty()     slug = ndb.stringproperty() 

right use "col" stringproperty hold kind (like "pages", "posts", etc) , query "col" every time.

after reading docs, stumbled upon @classmethod:

class mymodel(ndb.model):     @classmethod     def _get_kind(cls):          return 'anotherkind' 

does mean can this?

class dynamic(ndb.expando):     """     handles "post types", such pages, posts, users, products, etc...     """     col = ndb.stringproperty()     parent = ndb.integerproperty()     name = ndb.stringproperty()     slug = ndb.stringproperty()      @classmethod     def _get_kind(cls):         return 'anotherkind' 

but how dynamically replace 'anotherkind'? can return col?

thanks!

i don't know if can that, sounds dangerous, , gae updates might break code.

using subclasses seems safer alternative. this:

class dynamic(ndb.expando):     parent = ndb.integerproperty()     name = ndb.stringproperty()     slug = ndb.stringproperty()  class pages(dynamic):     pass  class posts(dynamic):     pass  class users(dynamic):     pass 

you try using polymodel.

we need know more application , trying accomplish give more specific advice.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -