How to prefetch related QuerySet in Django admin

Content

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 = my_model.prefetch_related('user')     return queryset
Posted . Did this help you? Please let me know with a comment. Thank you

Comments (RSS)