AppEngine NDB PolyModel获取属性 [英] AppEngine NDB PolyModel getting properties

查看:77
本文介绍了AppEngine NDB PolyModel获取属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的appengine出现了一个我似乎无法弄清的问题:

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()

因此,使用上述类,当我查询所有ItemInHouse,然后尝试访问具有MedicalItem的那些iteminhouse时,无法获得med_sub_type.那就是:

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)

在itm.item.med_sub_type处引发错误.我什至尝试过:itm.item._values["med_sub_type"].b_val,但这仍然抛出AttributeError:'Item'对象没有属性'med_sub_type'.我确实在class_属性中看到它具有ItemMedicalItem属性,但是我无法访问它.有什么想法吗?

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?

谢谢 乔恩

推荐答案

我担心您尝试做的事情可能无法实现-我不认为我曾期望将PolyModel实例存储为StructuredProperty值.这能解释您所看到的吗?您可能要在NDB项跟踪器中提交功能请求,但我不能保证将实现该功能请求.

I fear that what you are trying to do may not be possible -- I don't think I had anticipated storing PolyModel instances as StructuredProperty values. Does that explain what you are seeing? You may want to file a feature request at the NDB item tracker but I can't promise it will be implemented.

这篇关于AppEngine NDB PolyModel获取属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆