[Answer]-Custom User model in Python with socialaccount

1👍

Assume your project strucutre is something like below, and the codes of User(AbstractUser) are located in mysite/mysite/app1/models.py:

mysite/    (root folder for the project, put it anywhere in your disk. Most developers have a workspace folder(s) in computer)
    (other non-application things. E.g. a static/, README.md, ...)
    manage.py
    mysite/    (container for all applications. You can put applications directly under root folder, but not recommended)
        __init__.py
        settings.py
        urls.py
        wsgi.py
        app1/     (each application resides in its own folder. You don't want to put all models in one models.py file or all views in one view.py file, right?)
            __init__.py
            models.py
            views.py
            ......

Then the app_name is app1, i.e. AUTH_USER_MODEL = 'app1.User'. Meanwhile, you need to add mysite.app1 into INSTALLED_APPS in settings.py. This probably will solve you CommandError issue.

ADDED NOTES:

Each application, you can consider it as a module of your project. The app_name of the application is the folder name. If you have defined models in one application, must add it into INSTALLED_APPS in settings.py.

Manually creating a folder is not a good way. django-admin.py startapp is more recommended, because it together creates some common files for an application, e.g. init.py, models.py, view.py, …

Suggest you to go through the django quick-start guide, if you haven’t done it: https://docs.djangoproject.com/en/dev/intro/tutorial01/

👤ZZY

Leave a comment