Brandon Goll
Brandon Goll

Reputation: 3

Can't access models from seperate: ImportError: no module named "HealthNet.ActivityLog"

I've been working on a way to log the activity of a system for a school project in Python 3.4 and Django 1.9. I am currently trying to import a models.py file from my ActivityLog app into other applications in my HealthNet project to save the activity. The IDE I'm using (Pycharm), is telling me that my code is correct but I get the this error whenever I try to makemigrations/migrate/runserver:

ImportError: No module named 'HealthNet.ActivityLog'

Here is my file setup:

HealthNet
    ActivityLog
        Migrations
        __init__.py
        admin.py
        apps.py
        models.py
        tests.py
        views.py
    Appointments
        Migrations
        __init__.py
        admin.py
        apps.py
        models.py
        tests.py
        views.py
HealthNet
    __init__.py
    settings.py
    urls.py
    wsgi.py

I'm trying to import models.py from ActivityLog into views.py from Appointments.

Here's my code from models.py

from django.db import models


class Log(models.Model):
    logTime = models.DateTimeField()
    logEvent = models.CharField(max_length=500)

    def __str__(self):
        return self.logEvent

This is the import statement from views.py in the Appointment package, which is the line that the error is tracing back to:

from HealthNet.ActivityLog.models import Log

And here is my list of installed apps in my settings.py file:

INSTALLED_APPS = [
    'Appointment.apps.AppointmentConfig',
    'User.apps.UserConfig',
    'ActivityLog.apps.ActivitylogConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

]

Thank you!

Upvotes: 0

Views: 483

Answers (1)

Milen Louis
Milen Louis

Reputation: 223

from ActivityLog.models import Log

'ActivityLog' and 'Appointments' are apps. So add 'ActivityLog' and 'Appointments' to INSTALLED_APPS in settings.py

For eg:

    INSTALLED_APPS = [ 
    'Appointment.apps.AppointmentConfig',
    'User.apps.UserConfig',
    ..........................
    .........................
    'ActivityLog',
    'Appointments',
    ]

Try this. It will work.

Upvotes: 1

Related Questions