Skip to content

Commit da16c37

Browse files
authored
Avoid fetching table data in duplicate from ListView mixin
Fixes jieter#914.
1 parent cbac7ee commit da16c37

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

django_tables2/views.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Any, Optional
33

44
from django.core.exceptions import ImproperlyConfigured
5-
from django.views.generic.list import ListView
5+
from django.views.generic.list import ListView, MultipleObjectMixin as ConfoundingMultipleObjectMixin
66

77
from . import tables
88
from .config import RequestConfig
@@ -156,8 +156,17 @@ def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
156156
"""
157157
Overridden version of `.TemplateResponseMixin` to inject the table into
158158
the template's context.
159+
160+
Will avoid calling ``django.views.generic.list.ListView.get_context_data``
161+
if this mixin is combined with ``django.views.generic.list.ListView`` or
162+
similar, as presumably ListView.get_context_data is meant to fetch the
163+
same data as this function will fetch directly.
159164
"""
160-
context = super().get_context_data(**kwargs)
165+
context = (
166+
super(ConfoundingMultipleObjectMixin, self).get_context_data(**kwargs)
167+
if isinstance(self, ConfoundingMultipleObjectMixin) else
168+
super().get_context_data(**kwargs)
169+
)
161170
table = self.get_table(**self.get_table_kwargs())
162171
context[self.get_context_table_name(table)] = table
163172
return context

0 commit comments

Comments
 (0)