Trouble With Custom Django Querysets
Reading through some common Django books and tutorials, you will come upon the advice to encapsulate your ORM-related business logic inside custom model managers and custom querysets. In this article, I will try to persuade you no to. Or at the very least, to persuade you that the bar should be very high for introducing those constructs. What are custom managers / querysets? TODO The stated benefits: DRY principle High level logic is clear Codifies field semantics of a model – you can see how to interpret certain fields My beef with them Beef #1: Mixed semantics If you app grows beyond the starting phase, you model will certainly be used in multiple apps. E.g. if you have a content taxonomy model, it might be used for recommending similar content, and it might be used for determining user’s interests. ...