Get the key of logged-in user with no DB access in Django on Google App Engine?

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.

Answers


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.


Need Your Help

Change line properties on a plot from a different function

python matplotlib

I'm stuck with something which is probably easy to fix, but I couldn't find anybody having this same issue on the internet.

I need assistance with a python assignment

python loops while-loop

the instructions are: write a simple python program that is controlled by a while loop. The sentry variable must evaluate to something other than true or false. There must be an indication of wheth...