gjivanya
gjivanya

Reputation: 589

Import model from another project

I have 2 Django projects with their Postgres databases. And they run on two different Azure VM's.

They are models in each project which is usable by both projects. How can I import the model of Project1 in Project2?

Regards, Gegham

Upvotes: 0

Views: 450

Answers (1)

Saiful Islam
Saiful Islam

Reputation: 71

In your WSGI.py, add the path of your second project to the sys.path by

sys.path.append('/root').

In your settings.py of the first project, add 'project2.app2' to the INSTALLED_APPS list:

INSTALLED_APPS = [
    ...
    'app1',
    'project2.app2',
    ...
]

And then you should be able to easily import the models of your second project by using from project2.project2.models import *

This is worked for me.

Upvotes: 1

Related Questions