I created a class that subclasses ListView and two custom mixins which have implemented a get_context_data function. I wanted to override this function on the child class:
from django.views.generic import ListView
class ListSortedMixin(object):
def get_context_data(self, **kwargs):
print 'ListSortedMixin'
return kwargs
class ListPaginatedMixin(object):
def get_context_data(self, **kwargs):
print 'ListPaginatedMixin'
return kwargs
class MyListView(ListSortedMixin, ListPaginatedMixin, ListView):
def get_context_data(self, **context):
super(ListSortedMixin,self).get_context_data(**context)
super(ListPaginatedMixin,self).get_context_data(**context)
return context
When I execute MyListView it only prints "ListSortedMixin". For some reason python is executing ListSortedMixin.get_context_data in place of MyListView.get_context_data. Why?
If I change the inheritance order to ListPaginatedMixin, ListSortedMixin, ListView, ListPaginatedMixin.get_context_data is executed.
How can I override the get_context_data function?