Skip to content Skip to sidebar Skip to footer

One-to-many Gql Query And Putting Results Into A Dictionary

I have a google database called Main. class Main(db.Model): name = db.StringProperty() phone = db.StringProperty() There's another database Photo which references Main through

Solution 1:

It's a bit difficult to figure out what you want to achieve with the information you provided. Perhaps you can clarify further. But for now, is this what you mean?

class Name(webapp.RequestHandler):
  def get(self):
    names = db.GqlQuery('SELECT * FROM Main WHERE name=:1 LIMIT 1','Alan')
    photo_array = [] #initialize an array to store the photos dicts
    for name in names:
      for photos in name.photos: #go over all the Photo entities that reference 'Alan'
        #retrieve and put in a dictionary, and append to the photo_array
        photo_array.append({"photo1":photos.photo1, "photo2": photos.photo2})
    values = {'names':names, 'photos': photo_array}
    self.response.out.write(template.render('base.html', values))

Post a Comment for "One-to-many Gql Query And Putting Results Into A Dictionary"