Search code examples
djangodjango-modelsarchitecturedjango-project-architect

Two Django projects with common models and business logic


I have two Django Projects that have different use cases. There are reached using different domains. They are hosted in two different servers. Also each Django project has it's own database.

Now, both the projects have some models and some business logic common between them. I don't want to duplicate the code and data which shall be chaotic going forward. Also, I want the models and code (business logic) to be in sync (when models/code is altered).

Can anyone guide me towards a pattern that can help me attain the required architecture: 2 separate projects with common models and business logic.

Thanks in advance.


Solution

  • I've done this before. You will have to move the shared models and business into a new python package (better if you can create a django app that encapsulates these models), in a separate directory.

    Add this directory to your python path (the one that contains the package, not the package itself) and you should be able to use this code from within your projects.

    The only downside to this is having to configure PYTHON_PATH in your servers or having to copy manually this package into your runtimes