#16074: Class-based views clash get_context_data
------------------------------------+-------------------------------
               Reporter:  emyller   |          Owner:  nobody
                   Type:  Bug       |         Status:  new
              Milestone:            |      Component:  Generic views
                Version:  1.3       |       Severity:  Normal
             Resolution:            |       Keywords:  cbv
           Triage Stage:  Accepted  |      Has patch:  0
    Needs documentation:  0         |    Needs tests:  0
Patch needs improvement:  0         |  Easy pickings:  0
------------------------------------+-------------------------------

Comment (by lukeplant):

 Having looked at [http://rhettinger.wordpress.com/2011/05/26/super-
 considered-super/ this article], I think a better way to do this is to add
 the `super()` calls, but for every class that defines `get_context_data`
 and currently inherits from `object`, make it inherit from a base class
 like this instead:
 {{{
 #!python

 class GetContextDataRoot(object):
     def get_context_data(self):
         return {}

 }}}

 It doesn't actually have to be the same base class in each case, it just
 needs this method, and no other functionality that might be wanted for
 other reasons. The existence of a base class like this means that:

 1. It doesn't get into problems calling `get_context_data` on object.
 2. The use of `super()` means that other classes can be inserted into the
 MRO, so no data gets lost.

 So, if we have `SubClass1` and `SubClass2` that both inherit from
 `GetContextDataRoot` (or an equivalent class), and use super(), and then I
 write my own that inherits from both `SubClass1` and `SubClass2`, I get an
 MRO like this:

 `MyClass` -> `SubClass1` -> `SubClass2` -> `GetContextDataRoot`

 Which is what I want.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/16074#comment:4>
Django <https://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 django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to