I have two Django Projects where I use a lot of common models. Custom user classes, Algorithm classes, Product classes. The two projects are related to e-commerce, both run on different machines and serve completely different purposes.
However, considering that they have these models in “common”, I was wondering if it would be worth it to create a third, common project that serves as the “base” with the base models, and then both of these projects would import the common models from this base project.
This would also help as we can join the two different customer and product databases from both e-commerce websites into this big common database.
My questions are:
1) Does anybody have any experience with the possible overhead or can realistically estimate it? Joining the common parts of both Django projects will be necessary down the road, but I estimate there will be a lot of overhead in importing a third project (possibly in real-time).
2) What would be the best approach to importin this third project? I can think of multiple ways:
- Creating a packaged, installable Python module such as the existing ones on the internet (setuptools, lxml, tastypie) and importing that module into both Django projects;
- Having the project sit on a directory in a machine and importing from that path in real-time inside the Python file (have done it before, works but seems to have some overhead);
EDIT: Our common models/functionality, additionally, contain trade-secreted and patenteable content, therefore public distribution is out of the question. I am guessing the route would be to create something like a package, but not publicly distributed, only distributed and installed on the 2 specific machines.
Can anybody give some feedback on this?
Thank you
I would separate out the common models, ect… into it’s own python package. Then each project will have this package installed, or just install the package at the system level and they both can use it. If you handle this properly you shouldn’t have to change much of your imports and you can easily update the package by pushing a new egg to the server and installing via
easy_installorpip.This is the way that I currently have my projects setup. Common non-business logic is separated out into their own project and I create a package from this and then install and use like any other python library.
The little bit of extra work here can save you a lot of time and allows for transparent updating of your common code between various projects as well.