簡體   English   中英

AppEngine NDB PolyModel獲取屬性

[英]AppEngine NDB PolyModel getting properties

我的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_屬性中看到它具有ItemMedicalItem屬性,但是我無法訪問它。 有任何想法嗎?

謝謝喬恩

我擔心您嘗試做的事情可能無法實現-我認為我沒有想到將PolyModel實例存儲為StructuredProperty值。 這能解釋您所看到的嗎? 您可能想在NDB項目跟蹤器上提交功能請求,但我不能保證將實現該功能。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM