Model managers and inheritance

44 views
Skip to first unread message

Lorenzo Peña

unread,
Apr 12, 2018, 12:38:58 PM4/12/18
to Django developers (Contributions to Django itself)
Hello everyone!

I know there must be a good reason to have managers outside of models and having the current rules for "manager inheritance" upon abstract/concrete model inheritance. However, there are legitimate cases where you want to use manager mixins (very much like model mixins) in order to compose manager functionality. And most of the time, at least to me, the need of model mixins and manager mixins in order to be composed for each model/manager feels like a bad design approach.

Consider the case someone needs abstract model mixins in order to have common fields composable, so that defining several models with common field patterns is done nicely by inheriting the mixins. Now consider the case someone needs to equally compose manager functionality, in a way that matches the abstract model functionality. The current way to do it is also creating several manager mixins and composing them into specific managers for each model. At one point one starts thinking that this could be done through a single mixin (for both fields and manager methods reuse.)

My questions:

- Can you point me to a page/thread where it's stated why we need external manager classes instead of mixing the manager functionality with the model class?
- Is there any way to work this design decision around, so that composing model and manager functionality can be done without having to create mixins for both?

Thank you very much!
Reply all
Reply to author
Forward
0 new messages