I am working on a Django project and getting the following error when trying to import the User model from chat_app_backend.authentication in my models.py file:
ModuleNotFoundError: No module named 'chat_app_backend.authentication'
Here's the code from my models.py file from my chat.models:
from django.db import models
from chat_app_backend.authentication.models import User
class ChatRoom(models.Model):
owner = models.ForeignKey(User, on_delete=models.CASCADE)
picture = models.ImageField(upload_to='chatroom_pictures/', null=True, blank=True)
number_of_users = models.IntegerField()
messages = models.TextField()
Here's my installed apps:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'authentication.apps.AuthenticationConfig',
'chat.apps.ChatConfig'
]
here's my models.py of my authentication.models:
from django.contrib.auth.models import AbstractUser
from django.db import models
class User(AbstractUser):
bio = models.CharField(max_length=500)
profile_picture = models.ImageField(upload_to='profile_pictures/')
And here's my project's file structure:
chat_app_backend
-chat_app_backend
-authentication
-chat
-chat_app_backend
I have tried the solution provided in this post (Django : Unable to import model from another App), but it did not work for me.
Apparently, its not the issue related to only the user model, when I try to access even the UserSerializer, which is in the authentication app(serializers.py), its giving me the same error.
from chat_app_backend.authentication.serializers import UserSerializer
ModuleNotFoundError: No module named 'chat_app_backend.authentication'
here's the code for the serializers.py in the chat app:
from rest_framework import serializers
from .models import ChatRoom
from chat_app_backend.authentication.serializers import UserSerializer
class ChatRoomSerializer(serializers.ModelSerializer):
owner = UserSerializer(read_only=True)
class Meta:
model = ChatRoom
fields = ['id', 'owner', 'picture', 'number_of_users', 'messages']