Skip to content

Instantly share code, notes, and snippets.

@gilsonbp
Created January 31, 2018 21:27
Show Gist options
  • Save gilsonbp/47682fb09a15884722182a039b43cb6a to your computer and use it in GitHub Desktop.
Save gilsonbp/47682fb09a15884722182a039b43cb6a to your computer and use it in GitHub Desktop.
MIDDLEWARE para set_current_tenant
from django_multitenant import *
class SetCurrentTenantFromUser(object):
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
if request.user.is_authenticated():
if hasattr(request.user, 'cliente'):
set_current_tenant(request.user.usercliente.cliente)
response = self.get_response(request)
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment