Can ndb.KeyProperty refer to the base class of the model when using model inheritance?

I have some models that have a common set of properties that I defined in the base class of the model from which other models inherit:

class BaseUser(ndb.Model): name = ndb.StringProperty() class DerivedUserA(BaseUser): # some additional properties... class DerivedUserB(BaseUser): # some additional properties... 

In some other model, I need a reference to any BaseUser -derived model:

 class MainModel(ndb.Model): user = ndb.KeyProperty(kind = BaseUser) 

However, when I try to set the DerivedUserA entity key to the DerivedUserA property, GAE raises a BadValueError , stating that it expects a key with Good BaseUser , but it is assigned DerivedUserA .

If I remove the kind argument from my MainModel , it will work:

 class MainModel(ndb.Model): user = ndb.KeyProperty() 

I could live with this, but I would rather check that I am not trying to save any object in the MainModel.user property. Is there any way to do this?

+4
source share
2 answers
+3
source

The reason this does not work is because a parameter of the form KeyProperty() immediately goes into a string.
Since this is only a validation function, we might consider fixing it. If you like this idea, you can write a function request to the tracker: http://code.google.com/p/appengine-ndb-experiment/issues/list - this will be less heavy than PolyModel (although it Seems PolyModel may be what you are looking for anyway).

+3
source

All Articles