member_query = Member.query(Member.account==account)
member_query now contains a Query instance.
From there, you have a few options, but it seems that you would want to only grab ONE entity from this query. To do that, you'd say.
member = Member.query(Member.account==account).get()
Now, member is either None if the account doesn't exist, or will contain a Member model instance.
If you use .fetch(), you can specify the number of entities you want to retrieve as the first argument, or use None (or no arguments) to grab all. If there are a lot of entities that match this condition, this could be time consuming.
Another paradigm would be to iterate over the query and break or return on the first entity that matches your conditions. This paradigm would allow you to do on-the-fly conditionals not covered by your query parameters. For example...
for member in member_query:
if member.active:
return member
# No account
return None
Querying over this sort of membership model is less than ideal, however, because it will require a query to run every time. Of course, if you want a 'user' to have access to multiple 'profiles' (like Facebook User <-> Facebook Pages, as an example), you need something like this.
It's far more efficient to structure the list of "Profiles" that an account has access to, like so:
class UserAccount(ndb.Model):
"""User Account"""
"""List of keys which reference profiles this user can access"""
profiles = ndb.KeyProperty(repeated=True)
def fetch_profiles(self):
"""Returns a list of profile entities this user can access"""
return ndb.get_multi(profiles)
def can_user_access_profile(self, profile):
"""Returns True if user can access 'profile' (either a ndb.Model or ndb.Key)"""
if isinstance(profile, ndb.Model):
profile = profile.key() # Convert Model instances to a key
return profile in self.profiles
class Profile(ndb.Model):
# ...
As you can see, this also let's you quickly determine if a user has access to a given profile.