On Mon, Mar 1, 2010 at 12:40 PM, Stephen McDonald <[email protected]> wrote: > Hi there, > > I'm just getting an understanding around how managers from abstract > models are applied to a subclass model and it appears as though if a > model inherits from two abstract models that each define a manager > with the same attribute name, eg "objects", then normal mro applies > and the derived model picks up the manager from the one abstract model > and loses the other one. What are people's thoughts around changing > this behaviour so that the derived model's "objects" attribute is > actually a newly created type, using each of the abstract models' > managers as the bases for the new manager? > > For example the calls at the end of this would work: > > class ManagerA(Manager): > def methodA(self): > pass > > class ModelA(Model): > objects = ManagerA() > class Meta: > abstract = True > > class ManagerB(Manager): > def methodB(self): > pass > > class ModelB(Model): > objects = ManagerB() > class Meta: > abstract = True > > class ModelC(ModelA, ModelB): > pass > > ModelC.objects.methodA() > ModelC.objects.methodB() > > It seems to me that this would be desired behaviour especially if the > abstract models are parts from separate applications that weren't > aware of each other, with each of their managers providing required > functionality. > > I've started working on a patch for this and I'm just looking for some > feedback before I go any further.
The only feedback I can give is that Django doesn't really support multiple inheritance in any capacity at the moment. Most of the internals for inheritance assume a single inheritance chain, not an inheritance tree. There might be some cases where inheritance it will work, but that will be mostly accidental, not intentional, and I suspect the model metadata will be a little messed up in those situations. So - you're in pretty much uncharted territory. Any change in this area will require some non-trivial plumbing changes. Broadly speaking, what you're talking about makes sense (i.e., that the ModelC manager should be a composed subclass). However, be warned - we're unlikely to accept that does the job piecemeal. If we're going to pursue multiple inheritance in models, we're going to want to ensure that it works across the board, not just pick and choose small isolated bugfixes. Yours, Russ Magee %-) -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
