ndb是否具有list属性

2024-04-19 18:28:21 发布

您现在位置:Python中文网/ 问答频道 /正文

而不是单个StringProperty(), 我想存储字符串列表

class BlogPost(ndb.Model):
    s1 = ndb.StringProperty(required=True)
    s2 = ndb.StringProperty(required=True)
    s3 = ndb.StringProperty(required=True)

我宁愿去

class BlogPost(ndb.Model):
    my_strings = ndb.StringListProperty() # does this exist?

Tags: 字符串true列表models3myrequiredclass
2条回答

另外,如果您只在列表上操作,并且不需要索引,那么可以使用ndb.JsonProperty来解析具有非空的有效Json对象的列表。通过这种方式,您还可以压缩数据,但如果不将其启用为arg,则会丢失索引,因为它存储为Blob。

是,使用重复属性:

Any property with repeated=True becomes a repeated property. The property takes a list of values of the underlying type, rather than a single value. For example, the value of a property defined with IntegerProperty(repeated=True) is a list of integers.

查看文档:Repeated Properties

相关问题 更多 >