views:

25

answers:

1

I'm using Django on GAE. When I say user = request.user, I believe it hits the datastore to fetch the User entity.

I would like to just get the key for the currently logged in user, because that will allow me to get the user-related data I need from the memcache.

+1  A: 

You probably are still going to hit the DB once to get the session record, which is where the user_id field is stored. Then you may need to side-step the lazy evaluation done in the django.contrib.auth.middleware code. It's not difficult, but you need to read the code and find exactly the info you want and then get at it without triggering any of the magic.

Oh, and if you want to mumble your way through the Session objects directly you will have to call session.get_decoded() to get a dict. The field you want (if it exists) is _auth_user_id.

Peter Rowell