2
搜索谷歌提供的文檔並瀏覽所以我還沒有找到一種方法來檢索在db.Property對象上設置的選項(我想檢索它以創建基於模型)。檢索db.Property選項
我使用下面的食譜來做我需要的東西,這是正確的嗎?還有其他的方式嗎? (更簡單,更優雅,更Python等)
對於這樣一個模型:
class PhoneNumber(db.Model):
contact = db.ReferenceProperty(Contact,
collection_name='phone_numbers')
phone_type = db.StringProperty(choices=('home', 'work'))
number = db.PhoneNumberProperty()
我做了以下修改:
class PhoneNumber(db.Model):
_phone_types = ('home', 'work')
contact = db.ReferenceProperty(Contact,
collection_name='phone_numbers')
phone_type = db.StringProperty(choices=_phone_types)
number = db.PhoneNumberProperty()
@classmethod
def get_phone_types(self):
return self._phone_types
我完全錯過了使用目錄。謝謝。 – 2012-02-21 01:18:42
在ndb中,該屬性似乎是'_choices'。 – 2014-08-13 01:17:49