Am trying to get all the entities in my datastore,and then display them using HTML. Am trying to do this from inside a RequestHandler but i get the error message
"AttributeError: type object 'Student' has no attribute 'all'"
This is my Student class
class Student(ndb.Model):
banner_id = ndb.IntegerProperty(required=True)
name=ndb.StringProperty()
score=ndb.IntegerProperty()
And this is the RequestHandler code:
class MainHandler(webapp2.RequestHandler):
def get(self):
# Create a HTML table
table = "<html><head><title>Students Server</title></head><body><table><th>name</th><td>score</th>"
# Now get a list of all students
sqry = Student.all()
sqry.order('name')
# Use the data collected so far to create a table row and add
# it to the table
table += Student.toTableRow(score)
# Complete the table
table += "</table>"
self.response.write(table)
self.response.write(studentRegistrationPage)
Am trying to retrieve all the students and order the list based on name. Got this idea from here where an example like this was given.
# Order alphabetically by last name:
q = Person.all()
q.order('last_name')
# Order by height, tallest to shortest:
q = Person.all()
q.order('-height')
What am i doing wrong?
You are trying to perform a db query but you are using ndb.
Have a read of the docs https://developers.google.com/appengine/docs/python/ndb/queries . Also look at the db/ndb cheat sheet https://docs.google.com/document/d/1AefylbadN456_Z7BZOpZEXDq8cR8LYu7QgI7bt5V0Iw/mobilebasic?pli=1
With ndb the query would be Person.query()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With