def prefetch_modeladmin_get_queryset(modeladmin, *lookups):
 def do_wrap(f):
  @wraps(f)
  def wrapper(request, *args, **kwargs):
   qs = f(request, *args, **kwargs)
   qs = qs.prefetch_related(*lookups)
   return qs
  return wrapper
 modeladmin.get_queryset = do_wrap(modeladmin.get_queryset)

def prefetch_modeladmin_get_queryset ( modeladmin , * lookups ) : def do_wrap ( f ) : @ wraps ( f ) def wrapper ( request , * args , ** kwargs ) : qs = f ( request , * args , ** kwargs ) qs = qs . prefetch_related ( * lookups ) return qs return wrapper modeladmin . get_queryset = do_wrap ( modeladmin . get_queryset )
wraps default modeladmin get_queryset to prefetch related lookups .