Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8300225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:28:32+00:00 2026-06-08T16:28:32+00:00

I would like to create movies database, where user will be able to mark

  • 0

I would like to create movies database, where user will be able to mark movies he/she watched and liked:

class Movies(ndb.Model):
    watched = ndb.UserProperty()
    liked = ndb.UserProperty()

Will that work? I use Google accounts.
How should I choose later all movies user liked?


Upd. I’ve followed systempuntoout approach and use the following code to save user choices:

user = users.get_current_user()
if user:
    userschoices = models.UsersChoices(
        movie=ndb.Key(models.Movies, movie_id), # TODO: what if movie_id is wrong?
        watched=True,
        user_id=user.user_id()
        )
    try:
        userschoices.put()
        self.response.out.write('1')
    except:
        self.response.out.write('0')

But if user makes his choice several times, then several records are added to the datastore…
Wouldn’t be it better just to save user id and movie id as keyname?

userschoices = models.UsersChoices.get_by_id(user.user_id() + '-' + movie_id)
if userschoices is None:
    userschoices = models.UsersChoices(id=user.user_id() + '-' + movie_id)
userschoices.movie = ndb.Key(models.Movies, movie_id) # TODO: what if movie_id is wrong?
userschoices.user_id = user.user_id()
if option == 'liked':
    userschoices.liked = True
elif option == 'watched':
    userschoices.watched = True

However, with such approach if I don’t pass liked, then it overwrites its value with None (the same with watched, if not passed, None is used).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T16:28:44+00:00Added an answer on June 8, 2026 at 4:28 pm

    I would go with two different Models, one that stores all the Movies details and one to store the 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 informations about users you should create your UserInfo Model, keyed by user_id from the users API, with all the details Properties your application needs.

    class UserInfo(ndb.Model):
            #Keyed by user_id 
            nickname = ndb.StringProperty()
            email = ndb.StringProperty()
    

    To create a new UserInfo, you could 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/her user_id to retrieve the watched/liked 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())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create a class that runs something (a runnable) at regular
I would like to create a poster showing the movies I've seen, in this
i would like create a array of structure which have a dynamic array :
I would like to create this shape using just css. I am pretty sure
I would like to create a c++ type that mimic the build-in type exactly.
I would like to create a json object to send as a post array,
I would like to create set of strings and below is the only limitation.
I would like to create a virtual host in apache2, but I want it
I would like to create and hold on to an iterator_range. The range is
I would like to create an application which can learn to classify a sequence

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.