0
我有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_type。即:
itms = ItemInHouse.query(ItemInHouse.item.type == "Medical").fetch()
for itm in itms:
self.response.out.write(itm.item.med_sub_type)
在itm.item.med_sub_type处引发错误。我甚至尝试过:itm.item._values["med_sub_type"].b_val
,但是这仍然会抛出一个AttributeError:'Item'对象没有属性'med_sub_type'。我在class_
属性中看到它有Item
和MedicalItem
属性,但我无法访问它。有任何想法吗?
感谢 乔恩
如果有足够的需求,我会很高兴刺戳实施它。 – bossylobster
我认为这将是可怕的 – Jon