programmer
programmer

Reputation: 1

How can I import a django model from one project into another project, both the projects use same database

File structure -

root/

project1/
        app1/models.py
        project1/

project2/
        app2/views.py
        project2/

Now I want to import a model from project1/app1/models.py into project2/app2/views.py .

How can I achieve this?

I had a larger django project earlier but I have to split the project into different micro-services due to dependency issues.

Upvotes: 0

Views: 653

Answers (2)

Simone Pozzoli
Simone Pozzoli

Reputation: 107

I think you shouldn't do that, you don't want to have direct dependencies between different Django projects, it would be a mess to maintain. I suggest to try to figure out a different solution such as providing APIs to communicate between projects or using an AMQP broker.

Upvotes: 0

boyenec
boyenec

Reputation: 1627

You need to be use import in your views.py. here is an example how you can import project1 in your project2 views.

model.py

class project1(models.Model)
     ......

class project2(models.Model)
      .....

views.py

from .models import project1

def Project2view(request):
    project1 = project1.objects.all() 

Upvotes: 1

Related Questions