add properties to users google app engine

2019-05-20 23:03发布

What is the best way to save a user profile with Google App Engine (Python) ? What I did to solve this problem is create another Model, with a UserProperty, but requesting the profile from the user I have to do something like this:

if user:
    profile = Profile.all().filter('user =', user).fetch(1)
    if profile:
        property = s.get().property

Any ideas?

3条回答
兄弟一词,经得起流年.
2楼-- · 2019-05-20 23:41

This is not a solution but a warning.

user value is not a unique and stable identifier for a User. And the user_id property only exists for google users not for OpenId. So don't trust this solution.

查看更多
太酷不给撩
3楼-- · 2019-05-20 23:52

If you make the user_id of the user the key_name of the user's Profile entity, you can fetch it using Profile.get_by_key_name(), which will be faster than querying and then fetching.

Memcaching including the user_id as part of the key will allow even faster access to the profile.

查看更多
欢心
4楼-- · 2019-05-20 23:52

No, this is a pretty correct approach (though you might want to also store some of those profiles in memcache, of course;-). It's going to be fast, since there will be an index on the user field. You sure can't modify the Google-supplied user model, if that's what you're asking.

查看更多
登录 后发表回答