following is my settings.py installed app section
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
# third party
'rest_framework',
'rest_framework.authtoken',
'rest_auth',
'allauth',
'allauth.account',
'allauth.socialaccount',
'rest_auth.registration',
'corsheaders',
'crispy_forms',
# local apps
'users.apps.UsersConfig',
]
AUTH_USER_MODEL = 'users.CustomUser'
following is my apps.py file content
from django.apps import AppConfig
class UsersConfig(AppConfig):
name = 'users'
def ready(self):
import users.signals
following is my signal.py file content
from django.db.models.signals import post_save
from django.contrib.auth.models import User
from django.dispatch import receiver
from .models import Profile
@receiver(post_save, sender=User)
def create_profile(sender, instance, created, **kwargs):
if created:
Profile.objects.create(user=instance)
@receiver(post_save, sender=User)
def save_profile(sender, instance, **kwargs):
instance.profile.save()
init.py file in users app is empty
when I run command python manage.py makemigrations it gives error ModuleNotFoundError: No module named 'users.users' and also it shows error "No module named users" in the following line in apps.py import users.signals
my project directory sctructure screenshot is as shown in attached picture [enter image description here][1]
[1]: https://i.sstatic.net/PNU7p.png
with reference to above django configuration/code what correction in needed to resolve error in apps.py so that no module named users is resolved and signals are loaded correctly for the users app
edit: as needed by another user for providing solution my current custom user model in development is as below
from django.contrib.auth.models import AbstractUser
from django.db import models
from django.utils.translation import ugettext_lazy as _
from .managers import CustomUserManager
class CustomUser(AbstractUser):
CHOICES = (
('T', 'Teacher'),
('I', 'Institute'),
('S', 'Student'),
)
role = models.CharField(max_length=1, choices=CHOICES)
email = models.EmailField(_('email address'), unique=True)
date_of_birth = models.DateField(blank=True, null=True)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []
objects = CustomUserManager()
def __str__(self):
return self.email
class Student(models.Model):
user_student = models.OneToOneField(
CustomUser, on_delete=models.CASCADE, related_name="student_account"
)
standard = models.IntegerField(blank=True, null=True)
class Profile(models.Model):
user_profile = models.OneToOneField(
CustomUser, on_delete=models.CASCADE, related_name="profile"
)
location = models.CharField(max_length=140, blank=True, null=True)
gender = models.CharField(max_length=140, default="Male", blank=True, null=True)
def __unicode__(self):
return u'Profile of user: %s' % self.user_profile.email
class Teacher(models.Model):
user_teacher = models.OneToOneField(
CustomUser, on_delete=models.CASCADE, related_name="teacher_account"
)
years_of_Experience = models.IntegerField(blank=True, null=True)
class Institute(models.Model):
user_institute = models.OneToOneField(
CustomUser, on_delete=models.CASCADE, related_name="Institute_account"
)
zip = models.CharField(max_length=30, null=True, blank=True)
class StudentProfile(models.Model):
user_student_profile = models.OneToOneField(
Student, on_delete=models.CASCADE, related_name="student_profile"
)
is_disabled = models.BooleanField(default=False, blank=True, null=True)
def __unicode__(self):
return u'Profile of Student: %s' % self.user_student_profile.user_student.email
class TeacherProfile(models.Model):
user_teacher_profile = models.OneToOneField(
Teacher, on_delete=models.CASCADE, related_name="teacher_profile"
)
subject = models.CharField(max_length=140, blank=True, null=True)
def __unicode__(self):
return u'Profile of teacher : %s' % self.user_teacher_profile.user_teacher.email
class InstituteProfile(models.Model):
user_institute_profile = models.OneToOneField(
Institute, on_delete=models.CASCADE, related_name="institute_profile"
)
subject = models.CharField(max_length=140, blank=True, null=True)
def __unicode__(self):
return u'Profile of Institute : %s' % self.user_institute_profile.user_institute.email
Everything looks fine. I think the reason for error is because of Order of apps in INSTALLED_APPS
.
Change your INSTALLED_APPS
like this and check.
INSTALLED_APPS = [
# local apps
'users.apps.UsersConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
# third party
'rest_framework',
'rest_framework.authtoken',
'rest_auth',
'allauth',
'allauth.account',
'allauth.socialaccount',
'rest_auth.registration',
'corsheaders',
'crispy_forms',
]