如何使用值列表定义实体 属性

How to define entity property with list of values

我的咨询实体有一个 consult_status 属性。如模型中定义:

consult_status = ndb.StringProperty() # Consult status: (Pending, Completed, Cancelled)

如评论中所示,我的状态可以具有三个值之一。我相信我应该使用列表而不是使用 StringProperty?我如何在我的模型中定义它而不是使用字符串?这是使用repeated=true的地方吗?

不,repeated=true 用于可以同时 多个值的属性。

对于您的用例,您正在寻找 choices 选项。来自 Property Options table:

choices

List of values of underlying type

Optional list of allowable values.

您仍在使用 StringProperty