juanefren
juanefren

Reputation: 2958

add properties to users google app engine

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?

Upvotes: 2

Views: 820

Answers (3)

fccoelho
fccoelho

Reputation: 6204

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.

Upvotes: 1

Wooble
Wooble

Reputation: 89857

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.

Upvotes: 4

Alex Martelli
Alex Martelli

Reputation: 881567

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.

Upvotes: 1

Related Questions