- Quick info about me and why I'm presenting on this topic.
What Are Model Managers? (3m)
- Dispel the idea that anyone isn't using MM. They're built in, even if people don't know it
- Review what is provided for you out of the box
- Explain the abstraction from the ORM
Talk about our sample project (2m)
- Introduce a sample project (perhaps the sample project from the Django docs) that we'll work through improving using MMs
Override the default Manager (3m)
- Basic setup
- QuerySet.as_manager() (more for free!)
Readability and Reuse (3m)
Readability is an easy win from using Model Managers and is a good first step toward understanding their benefits.
- Demonstrate chaning (composability) of Model Manager methods to improve readability
- DRY! - using Model Manager methods simplifies the repetition of writing the same queries across the codebase
Encapsulation of logic (5m)
Encapsulation is a major difference-maker for apps with significant business logic.
- Provide a consistent interface, even when the app evolves over time
- Effortlessly enable soft-deletes, etc.
- Preventing data leakage: protect future-you from present-you! (show an example of how much easier it is to use a Model Manager method than remembering to exclude records based on a status, etc)
- "Russian Doll" caching and applying the idea to queries
- Composeability of model manager methods allows you to selectively cache the results from Model Manager methods, particularly if non-query operations are going on there.