django-nonrel/djangotoolbox — pull request #40 by Alir3z4 (2013-05-19 23:07:27+00:00)
Title: Fix NotRegistered error when `AUTH_USER_MODEL` is defined

I'm trying to setup a stack of
* django-nonrel-1.5-beta
* django-mongodb-engine-1.5-beta
* djangotoolbox-1.5-beta

I have no problem with django-nonrel, django-mongodb-engine, But when I try to access to the admin or even running my app unit-tests I get `NotRegistered: The model User is not registered` error.

this is because of https://github.com/django-nonrel/djangotoolbox/blob/toolbox-1.4/djangotoolbox/admin.py#L21, which it should working actually, but I guess it breaks just because I'm using custom user model.

So when I've removed `AUTH_USER_MODEL` from `settings.py` it works, but with defining cutom user model it will not work at all, I think django itself is skip the creation of UserAdmin when there's a custom user model, this is why User model is `NotRegistered` happens.

```
File "/usr/lib/python2.7/site-packages/django/utils/functional.py", line 13, in _curried
return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs))
File "/usr/lib/python2.7/site-packages/django/db/models/base.py", line 1012, in get_absolute_url
return settings.ABSOLUTE_URL_OVERRIDES.get('%s.%s' % (opts.app_label, opts.module_name), func)(self, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/django/db/models/__init__.py", line 33, in inner
return reverse(bits[0], None, *bits[1:3])
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py", line 496, in reverse
return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py", line 382, in _reverse_with_prefix
possibilities = self.reverse_dict.getlist(lookup_view)
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py", line 297, in reverse_dict
self._populate()
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py", line 263, in _populate
for pattern in reversed(self.url_patterns):
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py", line 347, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py", line 342, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/alireza/dev/projekt/projekt/projekt/urls.py", line 10, in
admin.autodiscover()
File "/usr/lib/python2.7/site-packages/django/contrib/admin/__init__.py", line 29, in autodiscover
import_module('%s.admin' % app)
File "/usr/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/lib/python2.7/site-packages/djangotoolbox/admin.py", line 21, in
admin.site.unregister(User)
File "/usr/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 113, in unregister
raise NotRegistered('The model %s is not registered' % model.__name__)
NotRegistered: The model User is not registered

```