Wellfire Interactive // Expertise for established Django SaaS applications

This Old Pony: Decoupling from Django for great good

Tests, debugging, dependency upgrades - figuring out where to start with a “legacy” Django application can be a bigger headache than any technical problem.

To get started with our tips on maintaining Django apps and working with legacy projects, I want to start with a pattern that’s conceptually simple although not always easy: decoupling Django from your Django application. The framework for perfectionists gives us so much out of the box that it’s easy to run with it and forget that it’s a framework for delivering over the web, and not every component of every app is necessarily web related.

Take models, for instance. They’re the centerpiece for most apps because they hold the data. And since they’re data classes it’s sensible to start attaching lots of logic to them. You know, fat models and all that jazz. _ But now your application logic is forever tied to Django database models! _ You want to test that logic? Now you need to create model instances. Your models have database relations? Now you need to populate your test database with all kinds of model instances - or build a helpful if slightly fragile network of mocks.

A lot of the logic, even for only moderately complex CRUD apps, can live outside of models and be Django agnostic. This allows for faster, more robust testing, easier upgrade paths, and more options for reuse.

If you’re looking for some ideas on how to do this hit ‘Reply’ and tell me a bit about an app you’re having trouble with.

Until the next episode,

Ben, Co-founder & Chief Djangonaut

Learn from more articles like this how to make the most out of your existing Django site.