[英]NDB querying a GenericProperty in repeated Expando StructuredProperty
[英]ndb returning a StructuredProperty subproperty by querying for a StructuredProperty
嗨,我對如何返回StructuredProperty屬性(含糊)感到困惑:
假設我有來自ndb教程的以下示例:
class Address(ndb.Model):
type = ndb.StringProperty() # E.g., 'home', 'work'
street = ndb.StringProperty()
city = ndb.StringProperty()
class Contact(ndb.Model):
name = ndb.StringProperty()
addresses = ndb.StructuredProperty(Address, repeated=True)
guido = Contact(name='Guido',
addresses=[Address(type='home',
city='Amsterdam'),
Address(type='work',
street='Spear St',
city='SF')])
guido.put()
我希望能夠查詢阿姆斯特丹市,並使其返回類型“ home”。
因此,如果我執行查詢:
Contact.query(Contact.address == Address(city='Amsterdam'))
我希望它返回首頁。
默認情況下,appengine中的查詢會返回整個實體。 如果我對您的理解正確,則只需要返回結構化屬性的字段,而不是整個實體。
在這種情況下,您想閱讀投影查詢。
https://developers.google.com/appengine/docs/python/ndb/queries#projection
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.