#9317: Return content type of child class when parent passed to
ContentType.objects.get_for_model
-----------------------------------+----------------------------------------
          Reporter:  svetlyak40wt  |         Owner:  nobody     
            Status:  closed        |     Milestone:             
         Component:  Contrib apps  |       Version:  1.0        
        Resolution:  wontfix       |      Keywords:  contenttype
             Stage:  Unreviewed    |     Has_patch:  1          
        Needs_docs:  0             |   Needs_tests:  0          
Needs_better_patch:  0             |  
-----------------------------------+----------------------------------------
Changes (by mtredinnick):

  * status:  new => closed
  * needs_better_patch:  => 0
  * resolution:  => wontfix
  * needs_tests:  => 0
  * needs_docs:  => 0

Comment:

 I'm a strong -1 on this for reasons that have already been discussed a lot
 on both django-dev and django-users. This is related to why querying a
 parent model shouldn't automatically cast to the descendent instances
 (which aren't necessarily children, but could be grand-children or even
 further removed).

 Firstly, `get_for_model()` returns the content type for the model you pass
 in. You're trying to change that to return the content type for some
 other, related model (the instance you pass in *is* a `Parent`, it's not
 down-cast to be one of the child types, so the content type is the content
 type of `Parent`). For everybody, not just your call.

 Secondly, this is a very expensive operation. If a parent model has 3
 children, each of which have 3 children of their own, you've just executed
 ''at least'' 12 database lookups (possibly more if there are other
 `OneToOneFields` on the models -- you're heavily misusing
 `_collect_related()` here). Thirdly, there's the implementation issue that
 nothing outside the Model class should be using a method starting with an
 underscore.

 There's probably a useful utility set of functions that somebody could
 build (as a third-party application initially) that does things like
 descendent content types and down-casting to the right child,
 automatically looks for a field such as child_type, etc. But those
 utilities shouldn't initially be targeted at Django's core, since they
 don't need to modify anything there. Keep in mind the multi-layer, multi-
 child inheritance situation, since these things start to scale very poorly
 once you build up any type of significant hierarchy.

 So thanks for writing a patch, but this isn't appropriate as a regular use
 thing in core. There are too many drawbacks.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/9317#comment:1>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" 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-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to