Guido van Rossum's Ndb library for Google App Engine has a syntax for queries that I find curious. Suppose you wanted to find all happy users, you would write this query:
User.query(User.happy == True)
I read that as:
query method of the User class, which inherits from ndb.Model. Fine so far.User.happy, and a value, True.I would expect the expression to evaluate to False (much as dict.keys == True would), so the above should be equivalent to:
User.query(False)
How does Ndb do anything intelligent with that? What python magic am I missing?
You're missing python magic methods.
__eq__(self, other)
Defines behavior for the equality operator, ==.
Good guide about this could be found here.
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