On Fri, Jun 6, 2014 at 6:49 AM, Luis Masuelli <[email protected]> wrote:
> What about integrating polymorphic features in the ORM? It's like having > the features of django-polymorphic but in the core. > > The polymorphism could be acheved by: > 1. Having contenttypes installed (this is a common pattern). > 2. Specifying a root (first ancestor) model class like: > > class MyParentModel(models.Model): > ... > > class Meta: > polymorphic = True > discriminant = "somefield" #it could default to 'content_type' > if not specified. This field could be created. > > To achieve the polymorphism a query could be like: > > objects = > MyParentModel.objects.filter(foo=bar,baz=clorch,...).polymorphic().more().calls().ifneeded() > > Such method could complain if the contenttypes application is not > installed; it could be based on many select_related() arguments (which are > collected by tree-traversing the hierarchy, perhaps ignoring proxies). > Alternatively, this could be an util in the contenttypes app instead of > the core apps: > > objects = > contenttypes.utils.polymorphic(MyParentModel.objects.filter(foo=bar,baz=clorch,...)).more().calls().ifneeded() > > Sorry if this was posted before, but it's my first time here and I always > asked why does Django not have this feature in the core. > If you set your time machine to go back 6 years, you'll find the original discussions about model inheritance (implemented by Malcolm Tredinnick, and I did a whole bunch of design/implementation review): https://groups.google.com/forum/#!topic/django-developers/fUCtNz6_qRI In those discussions, we discussed the idea of introducing a CORBA-style narrow() function (which is what you're talking about here) due to the need to add and maintain extra columns, which aren't required for many applications. That said - the decision was at least partially in the interests of landing *something*. We've had 6 years to digest that design, and a bunch of internal API cleanups in the process. Personally, I'm not fundamentally opposed to revisiting this issue - I've had a bunch of places where a narrow() call would have been useful. However, I *would* want it to be an opt-in feature of the model API. But I'd also warn - this isn't a small undertaking. This is going to be a big patch, and you're going to need a champion on the core team if you want to make serious progress in getting this into core. Yours, Russ Magee %-) -- You received this message because you are subscribed to the Google Groups "Django developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAJxq848kOPXpg7h8V%2B9%3DrJs%2BAQbz%2BeAhHksWcywnOMXMfZSamQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
