Shivank Kashyap
Shivank Kashyap

Reputation: 33

How to Import Models from one app to another App model?

I am trying to reference a model People from my users app, in the models-file of botschaft app. Unfortunately, I get an ModuleNotFoundError while doing make migrations.

here is my botschaft-models.py:

from django.db import models 

from loginSite.users.models import People

class Botschaft(models.Model):
      from_person = models.ForeignKey(People, related_name='from_person',on_delete= models.CASCADE)
      to_person = models.ForeignKey(People,related_name='to_person',on_delete= models.CASCADE)
      msg = models.TextField()

And directory structure of my project is as: directory structure of my project

While doing migrations , I am getting error as:

from loginSite.users.models import People

ModuleNotFoundError: No module named 'loginSite.users'

I have tried using -

from ..users.models import People

but getting error as,

from ..users.models import People
ValueError: attempted relative import beyond top-level package

Little help will be appreciated.

Upvotes: 0

Views: 233

Answers (1)

Shreyas Sreenivas
Shreyas Sreenivas

Reputation: 351

users.models should do it. Just make sure the app is added to the installed apps in your settings.py.

Upvotes: 1

Related Questions