Home > Enterprise >  Import model from another project
Import model from another project

Time:10-17

I have 2 Django projects with their Postgres databases. And they run on two different servers.

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

Regards, Gegham

CodePudding user response:

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.

  • Related