I don't know how django-tools solves it - but it usually is set for every
request to the server.

When running django you have 1 or more threads that run the server. Each
thread can handle one request at a time - others get queued (you don't
usually see this). So when the request is done the middleware should clear
the user (that's how I wrote it at least - it's perhaps overkill, but
better safe than sorry). The next incoming request will then have a new
user - even if it is the same user from the previous one.

Regards,

Andréas

2018-08-19 16:00 GMT+02:00 Fellipe Henrique <[email protected]>:

> Thanks Andreas,
>
> Using your tip, I installed django-tools app, and now I can get the
> current user junt using single line... :)
>
> One question... these locals variable, change for each connection?
> example:  I have 1 site, and I want to get several models, with FK for each
> user.. so.. User1 can only see data from him.. that's the reason I need to
> filter...  Works like these?
>
> T.·.F.·.A.·.     S+F
> *Fellipe Henrique P. Soares*
>
> e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \
> 's/(.)/chr(ord($1)-2*3)/ge'
> *Fedora Ambassador: https://fedoraproject.org/wiki/User:Fellipeh
> <https://fedoraproject.org/wiki/User:Fellipeh>*
> *Blog: *http:www.fellipeh.eti.br
> *GitHub: https://github.com/fellipeh <https://github.com/fellipeh>*
> *Twitter: @fh_bash*
>
>
> On Sun, Aug 19, 2018 at 5:14 AM Andréas Kühne <[email protected]>
> wrote:
>
>> What you can do is add a middleware that sets the current user in a
>> thread local variable. That way you can then add a custom model manager
>> that reads that variable.
>>
>> Then all of your filters will be set automatically.
>>
>> Regards,
>>
>> Andréas
>>
>> 2018-08-18 17:46 GMT+02:00 Fellipe Henrique <[email protected]>:
>>
>>> Thanks Jason,
>>>
>>> But, can I get current user on model manager? I need to filter with that
>>> info.
>>>
>>>
>>>
>>> T.·.F.·.A.·.     S+F
>>> *Fellipe Henrique P. Soares*
>>>
>>> e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \
>>> 's/(.)/chr(ord($1)-2*3)/ge'
>>> *Fedora Ambassador: https://fedoraproject.org/wiki/User:Fellipeh
>>> <https://fedoraproject.org/wiki/User:Fellipeh>*
>>> *Blog: *http:www.fellipeh.eti.br
>>> *GitHub: https://github.com/fellipeh <https://github.com/fellipeh>*
>>> *Twitter: @fh_bash*
>>>
>>>
>>> On Sat, Aug 18, 2018 at 9:10 AM Jason <[email protected]> wrote:
>>>
>>>> make a custom model manager for that model.
>>>>
>>>> https://docs.djangoproject.com/en/2.1/topics/db/managers/
>>>> #custom-managers
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Django users" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>> To post to this group, send email to [email protected].
>>>> Visit this group at https://groups.google.com/group/django-users.
>>>> To view this discussion on the web visit https://groups.google.com/d/
>>>> msgid/django-users/63e2765e-96a6-4283-ba6b-7c8ac5f25cb3%
>>>> 40googlegroups.com
>>>> <https://groups.google.com/d/msgid/django-users/63e2765e-96a6-4283-ba6b-7c8ac5f25cb3%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To post to this group, send email to [email protected].
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/django-users/CAF1jwZEoRS0%3DqOmoOcViUH_HseiLTe1670p6i%3DMQYBxG%
>>> 2BYeKjA%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CAF1jwZEoRS0%3DqOmoOcViUH_HseiLTe1670p6i%3DMQYBxG%2BYeKjA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/
>> msgid/django-users/CAK4qSCfOVv3K_kzbT_F1yaheHbH5sECdOp70nNcMi-3_m%
>> 3DtDXw%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAK4qSCfOVv3K_kzbT_F1yaheHbH5sECdOp70nNcMi-3_m%3DtDXw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAF1jwZGzK-Yd1qQb9FHY_3196bNjr_
> nsRkpraR5xB%2BwaTMxp%2Bg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAF1jwZGzK-Yd1qQb9FHY_3196bNjr_nsRkpraR5xB%2BwaTMxp%2Bg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK4qSCd3ggCk2DerMsdTNRCUkSYECWyHG3QXT7XdXMiDgV-N9A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to