简体   繁体   中英

Filtering of an Object's property's property in google app engine

In an App Engine app, I store registered members in a table that looks like this:

class Member(db.Model):
    user = db.UserProperty(required=True)
    #other stuff

The problem starts when I need to check if a User is already in my Member table. GAE documentation says user value is not guaranteed not to change in time since it is composed by the user object+email. So it will change if the user changes the e-mail on that account.

I am using OpenID. So I though about using User.federated_identity() as a stable identifier.

However to check for this I'd have to do a Query like this:

u = users.get_current_user()
rm = Member.all().filter('user_federated_identity =',u.federated_identity()).get()

This is a valid query in Django, but apparenty not in GAE. What can I do here, other that loading all my members to memory and checking their federated_identity?

You should be able to do this:

u = users.get_current_user()
rm = Member.all().filter('user =', u).get()

Maybe you can identify your user by a unique key_name:

key_name = "member/%s" % users.get_current_user ().user_id
user_ref = Member.get_or_insert (key_name)

GAE User API explicitly mentions user_id() as a permanent identifier that persists across e-mail changes. You can store it in separate field in model.

Note that it is only supported for Google Accounts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM