diff --git a/django_tables2/views.py b/django_tables2/views.py index 0a6ccab3..c698fcb1 100644 --- a/django_tables2/views.py +++ b/django_tables2/views.py @@ -3,6 +3,9 @@ from django.core.exceptions import ImproperlyConfigured from django.views.generic.list import ListView +from django.views.generic.list import ( + MultipleObjectMixin as ConfoundingMultipleObjectMixin, +) from . import tables from .config import RequestConfig @@ -146,8 +149,19 @@ def get_table_kwargs(self): return {} def get_context_data(self, **kwargs: Any) -> dict[str, Any]: - """Overridden version of `.TemplateResponseMixin` to inject the table into the template's context.""" - context = super().get_context_data(**kwargs) + """ + 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(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