from .models import Organization


class OrganizationMiddleware(object):

    def process_request(self, request):
        try:
            self.organization = Organization.objects.get(
                slug=request.subdomain
            )
        except Organization.DoesNotExist:
            pass

@@ -1,8 +1,62 @@
+from django.utils.functional import SimpleLazyObject%0A%0A
 from .mo
@@ -173,44 +173,71 @@
     
-try:%0A            self.organization =
+def get_organization():%0A            try:%0A                return
  Org
@@ -258,33 +258,16 @@
 cts.get(
-%0A                
 slug=req
@@ -284,31 +284,22 @@
 main
+)
 %0A
-    
       
-  )%0A
       
-  
 exce
@@ -344,9 +344,86 @@
     
-pass
+    return None%0A        request.organization = SimpleLazyObject(get_organization)
 %0A

Use SimpleLazyObject in OrganizationMiddleware