In general, this violates the logic of the DJango work. It is proposed to carry an object request manually, and, yes, do client.objects.filter (user = request.user) . If this is done many times, you can also arrange in the function:
# models.py def open_clients ( readst ): Retu SPAN> Client.objects. filter (user = redest.user) ... and, accordingly, use:
# views.py from .models IMPort ..., OWN_CLIENTS ... ... WN_CLENTS (REQUEST). Class = ""> all
() pre> on the other hand, in principle, make a copy of the request local for the stream:
# Middleware.py Import Threading_Local_Storage.local () class Currentrequestmiddleware ( object ): def Process_request ( self, request ): _local_storage.request = request def get_current_request (): retu getttr (_ local_storage, "" redest "" , none ) def get_current_user (): request get_current_request () if request is none : retu none retu getttr (recoest, , none )
pre> in settings.py
add to midleware_classes this CurrentrequestMiddleware and then use, like yours: # ""># models.py from django.db import models from .midleware Import get_current_user class Ownmanager (Models.manager): Def get_queryseet ( self ): qs = super (Ownmanager, self) .get_querySet () retu qs. filter (user = get_current_user ()) class Client (models.model): ... own_objects = Ownmanager () But all this will work until the inteal device of the framework, and the guarantees that no one is created for each request, no one is created a separate stream He gave (although in fact this seems to be so). For example, I would not have entrusted for the performance of this when using it with Django-Geent.