KeyProperty のkind
検証が のサブクラスに対して機能しないようですPolyModel
。
from google.appengine.ext import ndb
from google.appengine.ext.ndb import polymodel
class Item(polymodel.PolyModel):
parent = ndb.KeyProperty(kind="Folder")
class Folder(Item):
title = ndb.StringProperty()
def add_item(self, item):
item.set_parent(self.key)
class File(Item):
pass
class Main(webapp2.RequestHandler):
def get(self):
rootfolder = Folder(title="root")
rootfolder.put()
# the next line raise exception
subfolder = Folder(title="Cool things", parent=rootfolder.key)
subfolder.put()
例外:
line 1935, in _validate
'Expected Key with kind=%r, got %r' % (self._kind, value))
BadValueError: Expected Key with kind='Folder', got Key('Item', 6544293208522752)
Can ndb.KeyProperty reference a base model class when using model inheritance?で Guido van Rossum が言ったのと同じように見え ますか?