Split Django application into two Python packages

236 Views Asked by At

I have a pretty large Django web application. The application is installed on a server and is working. It is divided into several Django apps, each with its own models and views.

The users of this application are also programmers, and sometimes they want to write scripts that manipulate the database. I want them to use the existing Django models.

However, I don't want them touching the big web application, they shouldn't be able to modify the views or write management commands that are installed on the server. Just scripts to run at their own convenience on their own private copy of the database. Ideally, they should be able to just pip install our-django-models.

What's the best way of splitting the application into two parts? One will have to be a very slimmed-down Django application with just the models (which, again, are split into different Django apps). The other will need to be based on the first one, and provide everything else - views, their business logic, settings, etc...

2

There are 2 best solutions below

4
On

What you describe seems really complex.

I would suggest to use Git (ex: github) and place the entirety of your code in there.

  • Have at least two branches: master[default], dev
  • Everything that will be production ready and will be pushed on your server, can be on the master branch.
  • All your developers can work on the dev branch, or create a branch of their own if they need to do something specific.
0
On

You should, maybe, have your django models isolated from the “real domain objects”. You would create a new package, with the domain object logic, and have your django model objects implement both the business objects and the django base class. Then you could implement each method by dispatching to the base class, and provide the necessary django stuff here (limiting its responsibilities to dealing with django only) Both the django team and the other team would be able to pip install our-real-domain-objects