db to ndb migration ... issue with collection_name

142 views
Skip to first unread message

Toto

unread,
Dec 30, 2012, 8:26:19 PM12/30/12
to google-a...@googlegroups.com
In my previous GAE app, I had something like a blog (Post and related Comment)
Posts and Comments where 2 different models such as

class Post(db.Model):
    headline = db.StringProperty(required = True)
    content = db.TextProperty(required = True)   
   
class Comment(db.Model):
    """ Comment object with many-to-one relationship """
    content = db.TextProperty(required = True) 
    post = db.ReferenceProperty(Post, collection_name='comment_set')

Now with db, thanks to the collection_name, I could easily find the comments referring to a post ( aka back reference) using post.comment_set

How are now back references handled in ndb?
Is there a preferred method?

Regards


Gianni

unread,
Dec 30, 2012, 9:30:48 PM12/30/12
to google-a...@googlegroups.com
Hi,
Guido explained very clearly how to do here.

Just add a property to the Post class 

    @property
    def comments(self):
        return Comment.query(Comment.post == self.key)

-- Gianni




--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-appengine/-/_W5mhfhwqBEJ.
To post to this group, send email to google-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.

Reply all
Reply to author
Forward
0 new messages