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:
-
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)
-
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.
- 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>
- 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.