views:

84

answers:

1

This is why I need to put user_id()'s in the Datastore:

A User value in the datastore does not get updated if the user changes her email address. This may be remedied in a future release. Until then, you can use the User value's user_id() as the user's stable unique identifier.

http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html#users%5FUser

Within the datastore, the value is equal to the email address plus the user's unique ID. If the user changes her email address, the new User value will not equal the original User value in datastore queries or when compared by the app. If your app needs a stable identifier that does not change, you can store the unique ID separately from the User value.

http://code.google.com/appengine/docs/python/users/userobjects.html

How do I do it?

And how did you know (or where did you look it up?)

A: 

The usual answer is "no property": If you need a stable identifier, it's probably because you're looking users up by it, in which case you should use it as the key name for the entity, like so:

class UserInfo(db.Model):
  is_admin = db.BooleanProperty(required=True, default=False)

user_info = UserInfo.get_or_insert(users.get_current_user().user_id())

If you really need to store an identifier for the user elsewhere, you can use a db.StringProperty to store the User ID.

Nick Johnson