I've got an auth application which is used instead of django's own auth
app, called authentication
. Typically projects will specify AUTH_USER_MODEL = 'authentication.User'
.
There are some other projects which utilise a separate authentication backend and an API which brings in additional fields/methods to the User
model.
Because this additional functionality isn't used by all projects I'd like it to be an optional sub-application to authentication
. Therefore I've added it to the package setup as an extra;
setup(
name='authentication',
extras_require={
"api_app": ["api_client>=3.0.1"],
},
api_app
is then added as a sub-application to authentication
:
- authentication
-- apps.py
-- models.py
-- api_app
--- apps.py
--- models.py
With this I've got two models for users, User
in authentication.models
and APIUser
in authentication.api_app.models
. For projects making use of APIUser
I've got the following settings;
# AUTH_USER_MODEL = 'authentication.User'
AUTH_USER_MODEL = 'authentication_api.APIUser' # Needs to be `app_label.Model`
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.humanize',
'django.contrib.messages',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.staticfiles',
'authentication',
'authentication.api_app',
'api_client'
]
api_app.__init__
default_app_config = 'authentication.api_app.apps.APIConfig'
The api_app
is defined as;
class APIConfig(AppConfig):
label = 'authentication_api' # in an attempt to support `app_label.Model` ref in settings
name = 'authentication.api_app'
verbose_name = "API Authentication"
With this configuration django thinks that authentication_api
isn't installed, but AUTH_USER_MODEL
only supports app_label.Model
and nothing more complex, so how can I set this application up to support the top level model or the sub-level model for AUTH_USER_MODEL
?
Error I'm getting with the above setup;
django.core.exceptions.ImproperlyConfigured:
AUTH_USER_MODEL refers to model 'authentication_api.APIUser' that has not been installed