Search code examples
pythongoogle-app-engineapp-engine-ndbgoogle-app-engine-python

Assign a key name in pre put hook: inheritance from a general ndb model


I have this (working) model:

class WorkingModel(ndb.Model):
    # ...some properties...
    def _pre_put_hook(self):
        self.key = ndb.Key(WorkingModel, slugify(self.name))

What if I want to generalize the solution via inheritance? i.e.:

class slugModel(ndb.Model):
    def _pre_put_hook(self):
        self.key = ndb.Key(???, slugify(self.name))

class WorkingModel(slugModel):
    name = ndb.StringProperty()

Solution

  • You can use self.__class__ as argument.