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

  • SEARCH
  • Home
  • 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 7813753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:58:39+00:00 2026-06-02T04:58:39+00:00

I am back into AppEngine development. And I am quite hang up with the

  • 0

I am back into AppEngine development.
And I am quite hang up with the Datastorage.

I am used to “ids”, building the website with links like “/view?id=322345” gets me the GuestBook entry with this id voilà.

But in AppEngine I always see the db.Key.from_path() method called and other stuff like “Ancestors” and “parents”.

In my project I have simple relationships like User->Phonenumbers, and I want to inspect each User via a GET url appending something id-like.
Should I use the User models key() or how is this in AppEngine achieved?

Currently if I want to add i.e. a PhoneNumber to the User I write the following:

class JoinHandler(webapp2.RequestHandler):
    def get(self):
        user_key = self.request.get('rlm')
        fon_number = PhoneNumber()
        fon_number.country = "deDE"
        fon_number.user = db.Key(user_key)
        fon_number.put()
        self.redirect("/")
  • 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-02T04:58:40+00:00Added an answer on June 2, 2026 at 4:58 am

    If you are using the numeric ids that are automatically assigned by the datastore when you put an entity, you can then retrieve the entity with the model’s get_by_id method:

    class User(db.Model):
        name = db.StringProperty()
        # etc.
    
    def AddUser(webapp2.RequestHandler):
        def get(self):
            newUser = User()
            newUser.name = self.request.get('name')
            # etc. assign all model properties
            newUser.put()
            # now, newUser.Key().id() contains the auto-assigned numeric id.
            # we can pass this value to our template and get it back via
            # a form paramter for subsequent operations.
    
    def ShowUser(webapp2.RequestHandler):
        def get(self):
            user_to_show_id = self.request.get('id')
            user_to_show = User.get_by_id(user_to_show_id)
            if user_to_show is not None:
                # populate the template parameters with the users's data
                # and render the template
            else:
                # The requested user does not exist, so
                # render an error message/page.
    

    Now, if you also want to store phone number entities that belong to a given user, you make store them such that their parent is the User entity. This puts them in the User’s entity group and entities that are in an entity group can be queried together more quickly than if they are stored with parents.

    Let’s say that any User can have any given number of Phonenumber entities associated with it:

    class Phonenumber(db.Model):
        number_type = db.StringProperty()
        number = db.StringProperty()
    

    We’ll add a method to the User class:

    def AddNumber(self, new_number_type, new_number):
        new_number = Phonenumber(parent=self, number_type=new_number_type, number=new_number)
        # In this case, self is the User entity, and by saying parent=self, we're putting
        # this Phonenumber entity into User's entity group.
        new_number.put()
    
    def GetPhoneNumber(self):
        # Now, getting all of User's phone numbers is a simple as a query with an
        # Ancestor clause:
        users_numbers = Phonenumber.all().ancestor(self).fetch(1000)
    
       return users_numbers
    

    Obviously, these classes are naive and straight off the top of my head, but I hope that they’ll help you understand both id’s and ancestor relationships. Often times, you won’t have to use Key() to manually create keys at all. Don’t go that route unless you really need to. Still, understanding how Keys work is good for really understanding AppEngine, so dive in and experiment if you feel like it.

    I think that those were your two main questions, yeah? If you have others, go ahead and leave a comment, and I’ll edit my answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a largely self-taught front-end developer only just making the transition into back-end development
I am just getting back into game development and I am really impressed with
I am back into c/Linux. The question might look stupid, but relevant after working
I'm getting back into web design after a several year break, so a lot
gcc I am just getting back into c programming and I am just practicing
I'm working with someone who's looking to get back into programming after several years
From a C background I find myself falling back into C habits where there
I encounter this issue pretty consistently when trying to merge a branch back into
I've dabbled with Haskell in the past, and recently got back into it seriously,
I've recently been doing a lot of Objective-C programming, and just got back into

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.