diff --git a/django_tables2/views.py b/django_tables2/views.py index b972c0a0..ce65b61e 100644 --- a/django_tables2/views.py +++ b/django_tables2/views.py @@ -2,7 +2,10 @@ from typing import Any, Optional from django.core.exceptions import ImproperlyConfigured -from django.views.generic.list import ListView +from django.views.generic.list import ( + ListView, + MultipleObjectMixin as ConfoundingMultipleObjectMixin, +) from . import tables from .config import RequestConfig @@ -156,8 +159,17 @@ def get_context_data(self, **kwargs: Any) -> dict[str, Any]: """ Overridden version of `.TemplateResponseMixin` to inject the table into the template's context. + + Will avoid calling ``django.views.generic.list.ListView.get_context_data`` + if this mixin is combined with ``django.views.generic.list.ListView`` or + similar, as presumably ListView.get_context_data is meant to fetch the + same data as this function will fetch directly. """ - context = super().get_context_data(**kwargs) + context = ( + super(ConfoundingMultipleObjectMixin, self).get_context_data(**kwargs) + if isinstance(self, ConfoundingMultipleObjectMixin) + else super().get_context_data(**kwargs) + ) table = self.get_table(**self.get_table_kwargs()) context[self.get_context_table_name(table)] = table return context