How can i access the current user outside a request in django
I'm working on a medium sized pr开发者_开发技巧oject 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.
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
There is no sane way to get the user outside of the request. If the current user matters then pass it to any functions that need it.
精彩评论