#App Structure and Custom User Models

6 messages · Page 1 of 1 (latest)

solar bronze
#

Hello all,

I've since restructured my project to avoid this issue, but I hit against something funny that feels like it should work, but doesn't.

Specifically, image this is your project structure, where you have an 'internal' app inside your project folder.

my_project/
  my_app/model.py #Custom user model here
  my_app/apps.py # AppConfig.name = 'my_project.my_app'
  settings.py

In your settings.py, you have:

INSTALLED_APPS = [
    ...
    "my_project.my_app"
]
AUTH_USER_MODEL = "my_project.my_app.User"

Then this will error, because the AUTH_USER_MODEL setting expects the app name to not have any dots in its path.

Is this expected? Is "embedding" apps inside the project just an anti-pattern / not intended? Because there are some projects out there with that structure e.g. healthchecks.io (https://github.com/healthchecks/healthchecks/tree/master)

GitHub

Open-source cron job and background task monitoring service, written in Python & Django - healthchecks/healthchecks

bitter dew
#

It's completely doable and some recommend it as a starting point.

The thing with the User model setting is that it's not a python path, by a reference to the model, which is the app_name.model_name.

#

You probably need to use the AppConfig.label setting as well

solar bronze
#

Oh, brilliant; yeah the label parameter absolutely works, thank you!

#

And happy new year 🙂