2013-01-19 24 views
0
我有AppEngine上的问题,我似乎无法弄清楚

的AppEngine NDB的PolyModel获取属性

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_属性中看到它有ItemMedicalItem属性,但我无法访问它。有任何想法吗?

感谢 乔恩

回答

2

我担心你正在尝试做的可能是不可能的 - 我不认为我所预期存储的PolyModel实例作为StructuredProperty值。这是否解释你所看到的?您可能想要在NDB物料跟踪器中提交功能请求,但我无法保证它会实施。

+0

如果有足够的需求,我会很高兴刺戳实施它。 – bossylobster

+0

我认为这将是可怕的 – Jon