I'm having some trouble understanding how entities and keys work in Google App Engine NDB.
I have a post
entity and a user
entity. How do I set the user_key
on post
to user
?
In the interactive console, I have this so far:
from google.appengine.ext import ndb
from app.lib.posts import Post
from app.lib.users import User
from random import shuffle
users = User.query()
posts = Post.query().fetch()
for post in posts:
post.user_key = shuffle(users)[0]
post.put()
I'm just trying to set up some seed data for development. I know this probably isn't the ideal way to set things, but my first question is:
- How do I get a key from an entity (the reverse is described in the docs)
- How do I set associations in ndb?
try:
Maybe this helps to understand the NDB. I had the same questions with you.