GAE NDB Expando Model with dynamic Kind
<p>Is it possible to assign a dynamic Entity Kind to an Expando Model? For example, I want to use this model for many types of dynamic entities:</p>

<pre><code>class Dynamic(ndb.Expando):
    """
    Handles all "Post types", such as Pages, Posts, Users, Products, etc...
    """
    col = ndb.StringProperty()
    parent = ndb.IntegerProperty()
    name = ndb.StringProperty()
    slug = ndb.StringProperty()
</code></pre>

<p>Right now I use the "col" <code>StringProperty</code> to hold the Kind (like "Pages", "Posts", etc) and query for the "col" every time.</p>

<p>After reading the docs, I stumbled upon this @classmethod:</p>

<pre><code>class MyModel(ndb.Model):
    @classmethod
    def _get_kind(cls):
         return 'AnotherKind'
</code></pre>

<p>Does that mean I can do this?</p>

<pre><code>class Dynamic(ndb.Expando):
    """
    Handles all "Post types", such as Pages, Posts, Users, Products, etc...
    """
    col = ndb.StringProperty()
    parent = ndb.IntegerProperty()
    name = ndb.StringProperty()
    slug = ndb.StringProperty()

    @classmethod
    def _get_kind(cls):
        return 'AnotherKind'
</code></pre>

<p>But how do I dynamically replace 'AnotherKind'? Can I do something like <code>return col</code>?</p>

<p>Thanks!</p>

<p>I don't know if you can do that, but it sounds dangerous, and GAE updates might break your code.</p>

<p>Using subclasses seems like a much safer alternative.  Something like this:</p>

<pre><code>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
</code></pre>

<p>You could also try using <code>PolyModel</code>.  </p>

<p>We need to know more about your application and what you are trying to accomplish to give more specific advice.</p>

python google-app-engine google-cloud-datastore app-engine-ndb