Search code examples
djangocookiecutter-django

Django Cookiecutter: How to import AUTH_USER_MODEL in config/settings/base.py?


As we know, Django-Cookiecutter has a different setup for settings files. The regular from django.conf import settings doesn't work here.

I want to reference to the custom user model defined in the base.py file in the settings directory. Any ideas?

Below is my project layout:

repository/
    config/
        settings/
            __init__.py
            base.py # where the auth_user_model variable is defined
            local.py
            production.py
            test.py
    app_dir/
        users/
            __init__.py
            models.py # where the custom user model is stored

I also tried to import the custom user model directly from users/models.py as below:

from users.models import User

But got the following error:

RuntimeError: Model class users.models.User doesn't declare an 
explicit app_label and isn't in an application in INSTALLED_APPS.

Solution

  • Tried the following, and it seems to work so far:

    from config.settings.base import AUTH_USER_MODEL