Given this model class
class Student(ndb.Model):
student_id = ndb.IntegerProperty(required=True)
student_name = ndb.StringProperty(required=True)
score=ndb.IntegerProperty(required=True)
def toJSON(self):
jsonData = {
"Student Id":str(self.student_id),
"Name":self.student_name,
"Score": str(self.score)
}
return json.encode(jsonData)
I am trying to run a query to return all the student names, along with the score for each student in JSON format.
I already ran a query on the datastore and was able to retrieve information regarding each student using
class ViewStudentDetailsHandler(webapp2.RequestHandler):
def get(self):
student_id=self.request.get('id')
callback = self.request.get('callback')
student = Student.get_by_id(student_id)
if student:
if (callback):
self.response.write(callback + '(' + student.toJSON() + ')')
else:
self.response.write(student.toJSON())
else:
if(callback):
self.response.write(callback + "(null)")
else:
self.response.write("No student with that id")
But have no clue how to get ALL
of the students.I have read examples given by Google, but am still lost.I know this time around i'll need a loop, but that's about all i can come up with.Any ideas would be appreaciated.