Skip to content

Commit

Permalink
fixup! Also prefetch customer with ChargeAdmin
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Sep 20, 2017
1 parent 3d9560f commit 1ed4168
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pinax/stripe/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib import admin
from django.contrib.admin.views.main import ChangeList
from django.contrib.auth import get_user_model
from django.db.models import Count, Q

Expand Down Expand Up @@ -105,15 +106,17 @@ def queryset(self, request, queryset):
return queryset.all()


class PrefetchingChangeList(admin.views.main.ChangeList):
class PrefetchingChangeList(ChangeList):
"""A custom changelist to prefetch related fields."""
def get_queryset(self, request):
qs = super().get_queryset(request)
qs = super(PrefetchingChangeList, self).get_queryset(request)

if subscription_status in self.list_display:
qs = qs.prefetch_related('subscription_set')
if 'customer' in self.list_display:
qs = qs.prefetch_related('customer')
if 'user' in self.list_display:
qs = qs.prefetch_related('user')
return qs


Expand Down

0 comments on commit 1ed4168

Please sign in to comment.