I would go with two different models, which stores all the Movies details and one for storing UserChoices :
class Movies(ndb.Model): title = ndb.StringProperty(required=True) director = ndb.StringProperty() whatever = ndb.StringProperty() class UsersChoices(ndb.Model): movie = ndb.KeyProperty(kind=Movies, required=True) watched = ndb.BooleanProperty(required=True) liked = ndb.BooleanProperty(required=True) user_id = ndb.StringProperty(required=True) @classmethod def get_liked_movies(cls, user_id): return cls.query(cls.user_id == user_id, cls.liked == true).fetch(10) @classmethod def get_watched_movies(cls, user_id): return cls.query(cls.user_id == user_id, cls.watched == true).fetch(10) @classmethod def get_by(cls, user_id, movie_key): return cls.query(cls.user_id == user_id, cls.movie == movie_key).get()
If you need to store user information, you must create your UserInfo model, using user_id , from the user API , with all the details of the properties of your application.
class UserInfo(ndb.Model):
To create a new UserInfo , you can do:
from google.appengine.api import users user = users.get_current_user() userinfo = UserInfo( id = user.user_id(), nickname = user.keyname(), email = user.email() ) userinfo.put()
Then, when the user is logged in, use his / t user_id to get watched / favorite movies.
from google.appengine.api import users user = users.get_current_user() userinfo = ndb.Key(UserInfo, user.user_id()).get() watched_movies = UsersChoices.get_watched_movies(userinfo.key.id()) liked_movies = UsersChoices.get_liked_movies(userinfo.key.id())
source share