when reading a python ndb api of google app engine, I cam across this line.
Guestbook.query().order(-Guestbook.post_date)
Guestbook is an entity class and post_date is a property class.
But how order function can take that as a input ? its not value its name, more specifically
its definition of class.
How to define function to take such an input ?
Guestbook.post_dateis an instance of a class that implements the__neg__method to return an object that will tell the database API to order by that column descending.Here’s a small example on how it works (obviously the real class is much more complex):