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 3794708
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:58:16+00:00 2026-05-19T12:58:16+00:00

I am learning how to use Google App Engine / Python. (webapp) I am

  • 0

I am learning how to use Google App Engine / Python. (webapp)

I am coming from Java (could be my problem!), where if I put objects in a Swing list box, it would invoke their toString() method for display purposes. When I selected one of them it would return the object and not just the representation of it generated by toString().

I have a Person model that holds a persons details:

class Person(db.Model):
  '''represents a single person'''
  first = db.StringProperty()
  last  = db.StringProperty()
  address = db.StringProperty()
  city  = db.StringProperty()
  region = db.StringProperty()
  postal = db.StringProperty()
  country = db.StringProperty()
  phone = db.StringProperty()
  cell = db.StringProperty()
  email = db.StringProperty()
  comment = db.StringProperty(multiline=True)

And a Reservation model that stores information about the room, and stores what Person belongs with the Reservation:

class Reservation(db.Model):
    '''represents a single reservation'''
    room = db.StringProperty()
    start_day = db.IntegerProperty()
    start_month = db.IntegerProperty()
    start_year  = db.IntegerProperty()
    end_day = db.IntegerProperty()
    end_month = db.IntegerProperty()
    end_year = db.IntegerProperty()
    percent_discount = db.IntegerProperty()
    comment = db.StringProperty(multiline=True)
    client = #what would go here?

To get the reservation info from the user, and put the reservation into the database, I have an HTML form with various fields including rooms, arrival date, departure date, etc. One of them includes a “client list” that gets the list of Persons that are already in the database:

    <select size="5" name="client_list"> 
    {% for person in clients %}
        <option>{{ person.first|escape }} {{ person.last|escape }}</option>
    {% endfor %}
</select>

This works to display the names, but then I don’t know how to store the selected “Person” or client into the Reservation in the following code:

class Bookings(webapp.RequestHandler):
    '''Handles all of the bookings'''
    def post(self):
        '''adds a new booking into the db'''
        reservation = models.Reservation()

        reservation.room = self.request.get('room')
        reservation.start_day = int(self.request.get('start_day'))
        reservation.start_month = util.month_to_int(self.request.get('start_month'))
        reservation.start_year = int(self.request.get('start_year'))
        reservation.end_day = int(self.request.get('end_day'))
        reservation.end_month = util.month_to_int(self.request.get('end_month'))
        reservation.end_year = int(self.request.get('end_year'))
        reservation.percent_discount = int(self.request.get('percent_discount'))
        reservation.comment = self.request.get('comment')
        #This would get the clients first + last name, but not the object Person
        #reservation.client = self.request.get('client_list')

        reservation.put()
        self.redirect('/bookings')

I started to look at Keys (specifically db.Key.from_path), and how every Person made in GAE generates a unique ID, but then I still don’t know how to get that unique ID assigned to a person from the list displayed in the HTML if all that is displayed is the persons name.

This seems like something that is possible, and possibly simple but after two days of searching I have come up with nothing. Let me know if I should provide any more information, this is my first post here at Stack Overflow! Thanks for any advise.

  • 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-05-19T12:58:16+00:00Added an answer on May 19, 2026 at 12:58 pm

    According to the documentation:

    Every model instance that has been stored in the datastore has a unique key that represents the object. The key() method of a model instance returns the Key object for the instance.

    So you have to pass client’s key, not full name. Fix your template code:

    <select size="5" name="client"> 
      {% for person in clients %}
        <option value="{{ person.key }}">
          {{ person.first|escape }} {{ person.last|escape }}
        </option>
      {% endfor %}
    </select>
    

    Point that <option> element has its own value attribute. And note that why I changed <select> element’s name from cleint_list to client is that it cannot select multiple items, but only one item.

    Then, retrieve the client instance by its key. According to the documentation:

    An application can retrieve a model instance for a given Key using the get() function.

    So insert the following code in your application:

    client_key = Key(self.request.get('client'))
    client = Person.get(client_key)
    if client is None:
        # in case the passed key isn't available
        return
    reservation.client = client
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are planning a web application to build on Google's App Engine platform. Is
I just started learning about servers, and I am messing around with Google's App
I am learning to use LabVIEW as part of my honours project, and was
I have been learning to use Emacs for a little while now. So far
I am learning to use polymorphism in C#, but cannot figure out this one.
I am learning to use the Dvorak keyboad layout, but I am not good
I'm learning how to use Greasemonkey, and was wondering what the @namespace metadata id
I am learning how to use NUnit. I have my main project in it's
Where is a good place to get started learning how to use jQuery? It
So in my simple learning website, I use the built in ASP.NET authentication system.

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.