class UserWrapper object _user_model None def _get_model self if self

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class UserWrapper(object):
_user_model = None
def _get_model(self):
if self._user_model is None:
from django.conf import settings
if not getattr(settings, 'AUTH_USER_MODEL', False):
self._user_model = BaseUser
try:
app_label, model_name = settings.AUTH_USER_MODEL.split('.')
self._user_model = models.get_model(app_label, model_name)
except (ImportError):
# TODO: Error logging
raise Exception("Big badaboom")
return self._user_model
_model = property(_get_model)
def _get_model_manager(self):
return self._get_model().objects
objects = property(_get_model_manager)
def __getattr__(self, name):
print "Get: %s = %s" % (name, getattr(self._model, name))
return getattr(self._model, name)
def __call__(self, *args, **kwargs):
r = self._model(*args, **kwargs)
return r
User = UserWrapper()