Python AppEngine NDB PolyModel获取属性

Python AppEngine NDB PolyModel获取属性,python,app-engine-ndb,polymodel,Python,App Engine Ndb,Polymodel,我对appengine有一个问题,我似乎无法解决: from google.appengine.ext import ndb from google.appengine.ext.ndb import polymodel class Item(polymodel.PolyModel): name = ndb.StringProperty() type = ndb.StringProperty(choices=["Medical","Food"]) sub_ca

我对appengine有一个问题,我似乎无法解决:

from google.appengine.ext import ndb
from google.appengine.ext.ndb import polymodel

class Item(polymodel.PolyModel):
      name = ndb.StringProperty()
      type = ndb.StringProperty(choices=["Medical","Food"])
      sub_category_type = ndb.StringProperty()
      sub_category_sub_type = ndb.StringProperty()

class MedicalItem(Item):
      med_sub_type = ndb.StringProperty()
      can_split_item = ndb.BooleanProperty()

class ItemInHouse(ndb.Model):
      item = ndb.StructuredProperty(Item)
      amount_of_item = ndb.FloatProperty()
因此,使用上面的类,当我查询所有ItemInHouse,然后尝试访问那些具有MedicalItem的ItemInHouse时,我无法获得med_sub_类型。即:

itms = ItemInHouse.query(ItemInHouse.item.type == "Medical").fetch()
for itm in itms:
    self.response.out.write(itm.item.med_sub_type)
在itm.item.med_子类型处引发错误。我甚至尝试过:
itm.item.\u values[“med\u sub\u type”].b\u val
但这仍然会抛出一个AttributeError:“item”对象没有属性“med\u sub\u type”。我确实在
属性中看到它有
MedicalItem
属性,但我无法访问它。有什么想法吗

谢谢
Jon

我担心您试图做的事情可能不可能实现--我想我没有预料到将多模型实例存储为StructuredProperty值。这能解释你所看到的吗?您可能想在NDB item tracker上提交一个功能请求,但我不能保证它会被实现。

如果有足够的需求,我很乐意尝试实现它。我认为这将非常棒