2

使用 db,它似乎是 myexpando.dynamic_properties(),但尝试在 ndb 中执行此操作时,我得到了 dynamic_properties 的 AttributeError。

在文档中找不到有关对此进行更改的任何内容。

4

1 回答 1

4

当您使用 ndb 时,您应该使用 _properties 来获取属性列表

    The db, ndb, users, urlfetch, and memcache modules are imported.
dev~cash-drawer> class X(ndb.Expando):
...    pass
... 
dev~cash-drawer> 
dev~cash-drawer> 
dev~cash-drawer> y = X()
dev~cash-drawer> y.a = ndb.GenericProperty()
dev~cash-drawer> y.a = 100
dev~cash-drawer> y.a
100
dev~cash-drawer> repr(y.a)
'100'
dev~cash-drawer> type(y.a)
<type 'int'>
dev~cash-drawer> y._properties
{'a': GenericProperty('a')}
dev~cash-drawer> 

请参阅文档 https://developers.google.com/appengine/docs/python/ndb/entities#expando

于 2013-04-09T04:09:00.373 回答