Django Пользовательская модель пользователя, модель сохранена в отдельном файле в папке
Я новичок в Django и работаю над проектом, в котором нужен пользователь. Я создал папки для моделей, представлений, URL и сериализаторов. Каждая функция имеет свой собственный файл в этих папках.
Все работает хорошо, пока я не переименую models.py
файл в users_model.py
или не перенесу его в папку models, которую я создал.
Когда я makemigrations
появляюсь следующая ошибка:
django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'app.AppUser' that has not been installed
backend/
├── config/
│ ├── __pycache__/
│ ├── __init__.py
│ ├── asgi.py
│ ├── settings.py
│ ├── urls.py
│ ├── wsgi.py
├── app/
│ ├── __pycache__/
│ ├── migrations/
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── models
│ │ ├── users_model.py
│ │ ├── model_for_featur_1
│ │ ├── model_for_featur_2
│ ├── serializer
│ │ ├── users_serializer.py
│ │ ├── serialize_for_featur_1
│ │ ├── serialize_for_featur_2
│ ├── views
│ │ ├── users_view.py
│ │ ├── view_for_featur_1
│ │ ├── view_for_featur_2
│ ├── urls
│ │ ├── url_for_featur_1
│ │ ├── url_for_featur_2
├── manage.py
Мой код:
users_model.py
class AppUser(AbstractBaseUser):
.
.
.
class MyUserManager(BaseUserManager):
def create_user(self, email, username, password):
.
.
def create_superuser(self, email, username, password):
.
.
Admin.py
.
.
admin.site.register(AppUser)
sittings.py
INSTALLED_APPS = [
.
.
"app",
]
AUTH_USER_MODEL = "app.AppUser"
Я пытался AUTH_USER_MODEL = "app.models.users_model.AppUser"
ValueError: Invalid model reference 'app.models.users_model.AppUser'. String model references must be of the form 'app_label.ModelName'.
Я пытался AUTH_USER_MODEL = "app.models.AppUser"
ValueError: Invalid model reference 'app.models.AppUser'. String model references must be of the form 'app_label.ModelName'.
вам нужно создать __init__.py
файл в папке models и он выглядит так:
## __init__.py
from .user import AppUser