Solution 1 :

Not sure if creating a class for both (ocassions and subject) is the right way to go (you might just want to add strings on Greeting class). Anyways, lets focus on Subject for a couple of things you are missing:

  1. You still need to map both classes on the Greeting class:

    class Greeting(ndb.Model):

     author = ndb.StructuredProperty(Author)
     content = ndb.StringProperty(indexed=False)
     date = ndb.DateTimeProperty(auto_now_add=True)
     subject = ndb.StructuredProperty(Subject)
     occassion = ndb.StructuredProperty(Occasion)
    
  2. Include the assignation on the
    def post(self) Post method:

     greeting.content = self.request.get('content')
     greeting.subject = Subject(
                       subject=self.request.get('subject'))
     greeting.occassion = Occasion(
                       occasion=self.request.get('event'))
     greeting.put()
    

*Notice the ‘event’ when creating the “occasion” object, it should match the “name” attribute for the “events” select html tag.

  1. HTML tags should be inside the <form…> and should look like this:
<form action="/sign?guestbook_name={{ guestbook_name }}" method="post">
        <div class="subject-area">
        <label for="subject">Subject:</label>
        <textarea id="subject" name="subject" rows="1"></textarea>
        </div>
        <div class="occasion-area">
        <label for="occasions">Choose an Occasion:</label>
            <select id="events" name="event">
            <option value="Christmas">Christmas</option>
            <option value="New Year">New Year</option>
            <option value="Easter">Easter</option>
            <option value="Australia Day">Australia day</option>
            </select>
        </div>
        <div><textarea name="content" class="input-block-level" rows="3"></textarea></div>
        <div><input type="submit" class="btn btn-large btn-primary" value="Sign Guestbook"></div>
 </form>
  1. Print the value on the html with the jinja2 syntax:
<div class="container">
  <!-- [START greetings] -->
  {% for greeting in greetings %}
  <div class="row">
    {% if greeting.author %}
      <b>{{ greeting.author.email }}
        {% if user and user.user_id() == greeting.author.identity %}
          (You)
        {% endif %}
      </b> wrote:
    {% else %}
      An anonymous person wrote:
    {% endif %}
    <blockquote>{{ greeting.subject.subject }}</blockquote>
    <blockquote>{{ greeting.occasion }}</blockquote>
    <blockquote>{{ greeting.content }}</blockquote>
  </div>
  {% endfor %}

With 1 and 2 you will correctly store the values on Datastore, you can check it out on Console > Datastore > Entities. With 3 and 4 you will be able to interact with the values from the frontend side.

Problem :

So im currently using the Google Guestbook Sample App and completely new to this.

What I want to do is create a textbox that lets the user put in a subject, and a drop down menu that has a list of occasions as well as a message to sign to the guestbook.

Ive added this in the HTML index file as shown below. This works fine and shows the content on the page.

<div class="subject-area">
    <label for="subject">Subject:</label>
    <textarea id="subject" name="subject" rows="1"></textarea>
    </div>

    <div class="occasion-area">

    <label for="occasions">Choose an Occasion:</label>
        <select id="events">
        <option value="Christmas">Christmas</option>
        <option value="New Year">New Year</option>
        <option value="Easter">Easter</option>
        <option value="Australia Day">Australia day</option>
        </select>
    </div>

In my python application I’ve added new Classes for Subject and Occasion for the datastore.

class Subject(ndb.Model):

subject = ndb.StringProperty(indexed=False)

class Occasion(ndb.Model):

occasion = ndb.StringProperty(indexed=False)

Now I want to store the subject and occasion value into DataStore but when I go to my DataStore it no entity as show in image link 1. Ive tried to get the values but didn’t seem to work.

greeting.subject = self.request.get('subject')
    greeting.put()

    greeting.occasion = self.request.get('occasion')
    greeting.put()

Once Ive submitted all of the values(message, subject, occasion) I want to display it all on the page after submitting but not quite sure on how to do that yet?

Heres what my page looks like so far – 2

Comments

Comment posted by JC98

I tested it with the same Guestbook tutorial with the above steps and it all went smooth. 500 is thrown on the client side. You can find error details by going to Stackdriver logging > Filter by App Engine , can you share more details of the error thrown in the logs?

Comment posted by JC98

I edited my response to show more details, if 500 persists please share error details on App Engine Stackdriver logs

By