Google App Engine (python): filter users based on custom fields
Question: i am using the `webapp2_extras.appengine.auth.models.User` service which
basically extends the `google.appengine.api.users model`. Now , I have custom
users registered with my application and they have a lot of custom fields. The
problem is i want to filter / (multi filter) all the users using various
custom fields. For example:

the user model has 2 fields `is_active` and `activation_key` now i want to
filter them using these fields, example:

    
    
    from google.appengine.api import users
    
    act_key = 'hw-2j38he63u83hd6hak3FshSqj3TGemn9'
    user = users.all().filter('is_active =', False).filter('activation_key =', act_key).get()
    if user:
      return True
    else:
      return False
    

what are the best possible ways to filter on the user model using custom
fields?

Edit:

Also tried the following:

    
    
    from webapp2_extras.appengine.auth.models import User
    
    query = User.query().filter('is_active =', False)
    print query
    

but this raises an error as follows:

    
    
    Traceback (most recent call last):
    File "/opt/google_appengine_1.6.4/google/appengine/ext/admin/__init__.py", line 320, in post
    exec(compiled_code, globals())
    File "<string>", line 6, in <module>
    File "lib/ndb/query.py", line 968, in filter
    raise TypeError('Cannot filter a non-Node argument; received %r' % arg)
    TypeError: Cannot filter a non-Node argument; received 'is_active ='
    


Answer: The syntax for querying on Expando properties in NDB is a little different to
how it's done in the old DB API, and is documented
[here](https://developers.google.com/appengine/docs/python/ndb/queries#properties_by_string).
Your query needs to look something like this:

    
    
    user = users.all().filter(ndb.GenericProperty('is_active') == False, ndb.GenericProperty('activation_key) == act_key).get()
    

