Omar Jandali
Omar Jandali

Reputation: 824

Accessing a single model between multiple apps - Django

I have a Django project with two app that are users and groups. I have a model named Friend in the users app. I want to access the model in the groups app. How can I import the Friend model from the users app within the groups app. I want to access the other models to make queries and querysets in the groups app from the models in the groups app.

Here are the import statements I have right now...

Imports for the views in the users app:

from .forms import *
from .method import *
from .models import *

Imports for the veiws in the groups app:

from .forms import *
from .models import *

How can i import the users models in the groups app. I also want to import the groups models in the users models.

Here is the current directory....

enter image description here

Upvotes: 1

Views: 2171

Answers (1)

mtt2p
mtt2p

Reputation: 1906

from [app].models import [model]

from user.models import  Class

Or

from groups.models import Class

Be sure you have created __init__.py files on every app directory

Upvotes: 3

Related Questions