简体   繁体   中英

Structured Property or any better way?

I'm building a blog for a project and I'm saving all post in a entity kind like this:

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

Now all my posts must have comments, what I tried to did was to save the comments in a StructuredProperty repeated in this way:

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

This way only works if you have already created a instance of this property, but this just replace the old comment with the new one. What I want to do is to save all comments and these comments to be related with its post in the best possible way. Any suggestions?

A repeated property is basically a list so you can add a comment like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM