How to prefetch related QuerySet in Django admin
Use prefetch_related
and select_related
in Django admin. Implement a custom get_queryset
method.
from django.contrib import admin
class MyModelAdmin(admin.ModelAdmin):
def get_queryset(self, request):
queryset = super(MyModelAdmin, self).get_queryset(request)
queryset = queryset.prefetch_related('user')
return queryset
1 comment
.queryset
changed to.get_queryset
in Django 1.6https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_queryset
Leave a Reply