Where to put business logic in Django?

thanks for the props Cristóbal!

for anyone curious, the architecture book in question may be found here, https://github.com/cosmicpython/book, altho the short answer is “if you’re doing this sort of architecture, probably don’t use django”. the reasoning is that, if your domain is complex enough to warrant formal DDD / Domain Modelling, then it’s no longer a CRUD app, and you’re outside the Django sweet spot really.

of course not everyone starts with a green field, so we’re hoping to build out some pointers in the final chapter for how to do these sorts of things when starting from a probably-django monolith, but they’re not fleshed out atm.

there is an appendix on “how to do Repository Pattern, Unit of Work Pattern, and Service Layer Pattern with django” – ie how to fully decouple your model from the Django ORM. it’s painstaking, but not complex.

3 Likes