Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i access the current user outside a request in django

Tags:

python

django

I'm working on a medium sized project in django and i want to be able to access the current user from within my query manager. I need to be able to design a custom manager to limit the results and querysets so that the current user only get's information related to him/her.

I've received a few suggestions, I've also seen the not so supported example of using threadlocals from a django middleware. However, i'm very confused as this seems to be most promising solution now. I am looking for a better way to do this, so i can gain access to the current user from within a model manager.

like image 200
Emotu Balogun Avatar asked Nov 29 '10 12:11

Emotu Balogun


1 Answers

you can store the user object in the session object and get it out when needed

refer to how-to-lookup-django-session-for-a-particular-user

like image 155
mossplix Avatar answered Oct 06 '22 01:10

mossplix