I am having a problem with appengine that I can't seem to figure out:
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()
So using the classes above, when I query for all ItemInHouse, and then I try to access those iteminhouse that have a MedicalItem, I am unable to get med_sub_type. That is:
itms = ItemInHouse.query(ItemInHouse.item.type == "Medical").fetch()
for itm in itms:
self.response.out.write(itm.item.med_sub_type)
Throws an error at the itm.item.med_sub_type. I have even tried: itm.item._values["med_sub_type"].b_val
but this still throws an AttributeError: 'Item' object has no attribute 'med_sub_type'. I do see in the class_
property it has Item
and MedicalItem
properties, but I am unable to acces it. Any ideas?
Thanks
Jon
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…