1

I've been reading through related articles regarding using same database for multiple django projects however, I have not been able to come up with a fix yet. I've tried relative and absolute pathing when importing but it gives "attempted relative import beyond top-level package" error when I try to access parent directory.

Project 1 gets the users to write to database by filling in a form and Project 2 retrieves data written in by users from database.

I'm using Postgresql for database. I've tried writing exactly same models.py for both projects but it seems like in database they appear as separate relations/tables. E.g. for table named school in both models.py, it would look like project1_school and project2_school in Postgres database.

Is there a way to write to and read from same tables of same database?

Thank you so much in advance.

joo hwan kwon
  • 119
  • 2
  • 8

1 Answers1

1

I think that you might be confuse with the difference between Projects and Applications.

Projects vs. apps

What’s the difference between a project and an app? An app is a Web application that does something – e.g., a Weblog system, a database of public records or a small poll app. A project is a collection of configuration and apps for a particular website. A project can contain multiple apps. An app can be in multiple projects.

Writing your first Django app, part 1

So in you particular case, I would say that your actual projects, both of them, could be applications of one project. The main reason, why I think this is a better approach, is that both are gonna use the same data, one application writes while the other retrieve it. One could even argue that they actually could be the same application. But this may depend on many factors of your business.

BTW, is really hard for me to imagine a situation where it would be a good idea to have two projects using the same database. Even if both projects need to share data, I would not think in using on database. I would try to solve it at an application level. But I you need for some reason to share information at database level, there are tools to connect both databases.

Community
  • 1
  • 1
cabesuon
  • 4,860
  • 2
  • 15
  • 24
  • Would it be possible to run each application on different ports? Because the reason I segregated them into different projects instead of application was to have separate settings.py for each and run them on different ports – joo hwan kwon Jan 29 '20 at 02:58
  • Take a look at this post [Run Django on multiple ports](https://stackoverflow.com/questions/3883497/run-django-on-multiple-ports) – cabesuon Jan 29 '20 at 03:15