class Registry(object):
    
    def __init__(self):
        self._brands = {}
    
    def register(self, domain, app_model, expression):
        # @@@ Validation: what if it is already registered?
        # @@@ Validation: what if app_model is invalid for INSTALLED_APPS
        # @@@ Validation: what if expression is not a valid Q expression
        if domain not in self._brands:
            self._brands[domain] = {}
        if not isinstance(app_model, basestring):
            app_model = "%s.%s" % (app_model._meta.app_label, app_model._meta.object_name)
        self._brands[domain][app_model] = expression
    
    def expression_for(self, domain, app_model):
        return self._brands.get(domain, {}).get(app_model)


registry = Registry()


def register(domain, app_model, expression):
    registry.register(domain, app_model, expression)

@@ -1,8 +1,43 @@
+from django.conf import settings%0A%0A%0A
 class Re
@@ -179,206 +179,149 @@
     
-# @@@ Validation: what 
 if 
-i
+no
 t is
- already registered?%0A        # @@@ Validation: what if app_model is invalid for INSTALLED_APPS%0A        # @@@ Validation: what if expression is not a valid Q expression
+instance(app_model, basestring):%0A            app_model = %22%25s.%25s%22 %25 (app_model._meta.app_label, app_model._meta.object_name)%0A        
 %0A   
@@ -335,20 +335,16 @@
  domain 
-not 
 in self.
@@ -368,119 +368,193 @@
     
-self._brands%5Bdomain%5D = %7B%7D%0A        if not isinstance(app_model, basestring):%0A            app_model = %22%25s.%25s
+raise Exception(%22'%25s' is already registered.%22 %25 domain)%0A        if app_model.split(%22.%22)%5B0%5D not in settings.INSTALLED_APPS:%0A            raise Exception(%22'%25s' is not in INSTALLED_APPS
 %22 %25 
-(
 app_
@@ -563,54 +563,32 @@
 del.
-_meta.app_label, app_model._meta.object_name
+split(%22.%22)%5B0%5D
 )%0A
+        %0A
     
@@ -611,17 +611,20 @@
 %5Bdomain%5D
-%5B
+ = %7B
 app_mode
@@ -624,19 +624,17 @@
 pp_model
-%5D =
+:
  express
@@ -636,16 +636,17 @@
 pression
+%7D
 %0A    %0A  

Add some validation