Reputation: 993
Our site has two separate projects connected to the same database. This is implemented by importing the models from project1 into project2 and using it to access and manipulate data.
This works fine on our test server, but we are planning deployment and we decided we would rather have the projects on two separate machines, with the database on a third one.
I have been looking around for ideas on how to import the model from a project on another machine but that doesn't seem to be possible. An obvious solution would be to put the models in a separate app and have it on both boxes, but that means code is duplicated and changes have to be applied twice.
I'm looking for suggestions on how to deal with this and am wondering if other people have encountered similar issues. We'll be deploying on AWS if that helps. Thanks.
Upvotes: 2
Views: 320
Reputation: 9
I'm doing something similar, where I have two different Django Projects sharing a same database. So, in order to import the models what I did was to use a management/utility command of Django:
python manage.py inspectdb > yourapp/models.py
This will write your "models.py" file based on the table in the database you have connected to.
Then, once you have the models in project2's app, you can interact with DB using Django ORM as usual.
Go through this documentation and make customizations as needed.
Upvotes: 0
Reputation: 1148
This isn't really a Django question. It is more a Python Question.
However to answer your question Django is going to have to be able to import these files one way or another. If they are on seperate machines you really should refactor the code out into it's own app and then install this app on each of the machines.
The only other way I can think of to do this is to make your own import hook that can import a file from across a network but that is a really bad idea for a multitude of reasons.
Upvotes: 1