【问题标题】:Structured Property or any better way?结构化财产或任何更好的方法?
【发布时间】:2016-08-05 07:34:57
【问题描述】:

我正在为一个项目构建一个博客,并将所有帖子保存在这样的实体中:

class dbEntradas(ndb.Model):
    title= ndb.StringProperty(required=True)
    post= ndb.TextProperty(required=True)
    topic= ndb.StringProperty(required=True)
    user= ndb.StringProperty(required=True)

    comentarios= ndb.StructuredProperty(dbComentarios, repeated=True)
    #some others properties

现在我所有的帖子都必须有 cmets,我试图做的是将 cmets 保存在以这种方式重复的 StructuredProperty 中:

post.comentarios=[dbComentarios(usuario=usuario, asunto=asunto,
                        comentario=comentario)]

这种方法只有在你已经创建了这个属性的实例时才有效,但这只是用新的注释替换旧的注释。我想要做的是保存所有 cmets 和这些 cmets 以尽可能最好的方式与其帖子相关。有什么建议吗?

【问题讨论】:

    标签: python google-app-engine data-modeling google-cloud-datastore


    【解决方案1】:

    重复属性基本上是一个列表,因此您可以添加如下注释:

    post.comentarios.append(dbComentarios(usuario=usuario, asunto=asunto,
                            comentario=comentario)
    

    【讨论】:

      猜你喜欢
      • 2018-04-11
      • 2017-09-15
      • 2019-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-20
      • 1970-01-01
      相关资源
      最近更新 更多