views:

40

answers:

3

I have two different Django projects that are meant to run in parallel and do pretty different things.

However they need to share a common database table, the Client table..

Both projects contains multiple apps that needs to contain foreign keys mapped to that Client model..

I'm not sure what would be the best approach..

A: 

Assuming both projects are working on the same db, just import the model you want to reference to.

from first_project.some_app.models import Client, OtherSharedModel

class SomeModelInSecondProject(models.Model):
    client = models.ForeignKey(Client)
zalew
+2  A: 

Unfortunately, Django's support for multiple databases does not support cross-database relations. You could fake this on one of the systems (ie. have the table referenced, but handle the key refs yourself), but you would need to be very careful to document what you are doing to make sure you maintain referential integrity in the app that is 'faking' it.

Peter Rowell
A: 

I tried sharing database tables in two different Django projects.

In my first project, I created a test table in models.py, then in the second project, I imported the test table class from project1.app.models in views and tried to write to it. When I run the code I get a ViewDoesNotExist exception, saying that I cannot import project1.app.models because it does not exist.

Across different Django apps in the same project, this import worked for me perfectly. However I think different projects do not see each other's file path. Is there any way to make this work?

Any help would be appreciated.

Jd007