cant get ndb query results
Question: i just started learning python ndb i want to know how can i display students
attending a selected course (filtering Attendance) then mark their attendance
with a ardio button for each student,add the attendance value to the preveious
one and finally save the result back to the datastore or print it to file

# -_\- coding: cp1256 -_ -

    
    
    import webapp2
    import os
    import cgi
    from google.appengine.ext import ndb
    from google.appengine.api import users
    from google.appengine.api import mail
    from google.appengine.ext.webapp import template
    
    
    class Student(ndb.Model):
        id = ndb.IntegerProperty()
        name = ndb.StringProperty()
        email = ndb.StringProperty()
        #courses= ndb.StructuredProperty(Courses, repeated=True) and attendance
    
    class Course(ndb.Model):
        code=ndb.StringProperty()
        title=ndb.StringProperty()
        #time=ndb.TimeProperity
        #students= ndb.StructuredProperty(Students, repeated=True)
        #attendance  
    
    class Attendance(ndb.Model):
            courseCode=ndb.StructuredProperty(Course)
            #course=ndb.StructuredProperty(Course, repeated=True)
            date=ndb.StringProperty()
            #studentID=ndb.IntegerProperty(repeated=True)
            student=ndb.StructuredProperty(Student, repeated=True)
            attendance=ndb.IntegerProperty(repeated=True)# for each student
    
    
    class MainHandler(webapp2.RequestHandler):
        def get(self):
            #cerate ndb from file
            coursesfile = open('courses.txt', 'r').read()
            studentsfile = open('students.txt', 'r').read()
            dailyattendancefile = open('dailyattendance.txt','r').read()
    
            for line in coursesfile.split('\n'):
                line=coursesfile.split('\t')
                #stroe courses to datastore
                course=Course(code=line[0],title=line[1])#create Course entity
                course.put()
    
            for line in studentsfile.split('\n'):
                line=studentsfile.split('\t')
                student=Student(id=int(line[0]),name=line[1],email=line[2])
                student.put()
    
            for line in dailyattendancefile.split('\n'):
                line=dailyattendancefile.split('\t')
                attendance=Attendance(courseCode=Course(code=line[0]),date=line[1],student=Student(id=int(line[2])),attendance=int(line[3]))
                attendance.put()
    
    #print to html to test
            #self.response.out.write("<tr><td>"+ course.code + "</td>")
            #self.response.out.write("<td>"+ course.title+ "</td>")
            #self.response.out.write("</tr>")            
            self.response.out.write("""
            <html>
            <body>
            <form method="post" align="left">
                <select align="center" name="course_code">
                <option value="cs681" selected>CS681</option>
                <option value="cs681">CS611</option>
                </select>
    
                <input type="submit" value="Submit"/>
    
            """)
        def post(self):
    #get info from user
            coursecode=self.request.get('course_code')
            #self.response.out.write(Attendance.courseCode.code)
            self.response.out.write(""" 
        <table  align="center" >
            <tr align="center">
            <td>Course code</td>
            <td>Student ID</td>
            <td>Date</td>
            <td>Attendance</td>
        </tr>
    """)
            qry=Attendance.query(Attendance.courseCode.code==coursecode).fetch()
            for ent in qry:
                self.response.out.write('<tr><td>%s</td></tr>' %ent.courseCode)
    
            self.response.out.write("""
        </table>
    </form>
    </body>
    </html>
            """)
    
    app = webapp2.WSGIApplication([
        ('/', MainHandler)
    ], debug=True)
    


Answer: Try the following. I think you have a minor issue in your schema definition.

    
    
    class Course(ndb.Model):
        code=ndb.StringProperty(indexed=True)
        title=ndb.StringProperty()
    

