In Django, custom managers are a great way to organize reusable query logic. The Django documentation on Custom managers says:
There are two reasons you might want to customize a
Manager
: to add extraManager
methods, and/or to modify the initialQuerySet
theManager
returns.
However, it goes on to describe how custom QuerySet
classes can also be created, and that these can be made accessible directly from the data model as a manager using QuerySet.as_manager()
:
The
Manager
instance created byQuerySet.as_manager()
will be virtually identical to thePersonManager
from the previous example.
It seems like there is a lot of flexibility in how one could organize their logic between custom Manager
and/or custom QuerySet
classes. What are the principles by which I should decide when to use one versus the other?