lundi 23 novembre 2015

How to fetch repeated property values from GAE Datastore and pass the values into checkboxes

I am developing a web app which has a form that user can fill in their hobbies, interests and skills by checking each item pertaining to them from the groups of checkboxes.. below is my code:

This is the HTML Group of Checkbox code

      <span class="uk-form-label">Hobbies / Interests</span>
                    <div class="uk-form-controls">
                      <label class="uk-form-label"><input type="checkbox" name="hobbies-interests" id="movies" value="Movies">Movies</label>
                      <label class="uk-form-label"><input type="checkbox" name="hobbies-interests" id="adventures" value="Adventures">Adventures</label>
                      <label class="uk-form-label"><input type="checkbox" name="hobbies-interests" id="reading" value="Reading">Reading</label>
                      <label class="uk-form-label"><input type="checkbox" name="hobbies-interests" id="programming_tech" value="Programming">Programming</label>
                      <label class="uk-form-label"><input type="checkbox" name="hobbies-interests" id="board_games" value="Chess / Board Games">Chess / Board Games</label>
                      <label class="uk-form-label"><input type="checkbox" name="hobbies-interests" id="sports" value="Sports">Sports</label>
                      <label class="uk-form-label"><input type="checkbox" name="hobbies-interests" id="music_listening" value="Listening to Music">Listening to Music</label>
                      <label class="uk-form-label"><input type="checkbox" name="hobbies-interests" id="other_interests" value="Others">Others</label>
                  </div>

And I got all the checked values with my python code to store into the datastore:

    hobbies_interests=self.request.get_all('hobbies-interests')

This is the Model from the Python Class:

    class PersonalInfo(ndb.Model):    
        fullname = ndb.StringProperty()
        nickname = ndb.StringProperty()        
        hobbies_interests = ndb.StringProperty(repeated=True)

This is my query:

    personal_info = PersonalInfo.query().fetch()

So now, I want to get the values from hobbies_interests, so that when the html is loaded, the checkboxes that represent any of the values in hobbies_interests will all be checked automatically. So my question is how do I fetch the repeated values and use those values to auto check the hobbies-interests checkboxes.

Note, am also using Jinja2 Templating and Webapp2 Framework...




Aucun commentaire:

Enregistrer un commentaire