def _make_queryset_readonly(queryset):
 db_query_methods = ['count', 'get', 'get_or_create', 'latest', 'in_bulk', 'delete']
 for method_name in db_query_methods:
  method = getattr(queryset, method_name)
  wrapped_method = _wrap_with_readonly(method)
  setattr(queryset, method_name, wrapped_method)
 queryset.iterator = _wrap_generator_with_readonly(queryset.iterator)

def _make_queryset_readonly ( queryset ) : db_query_methods = [ 'count' , 'get' , 'get_or_create' , 'latest' , 'in_bulk' , 'delete' ] for method_name in db_query_methods : method = getattr ( queryset , method_name ) wrapped_method = _wrap_with_readonly ( method ) setattr ( queryset , method_name , wrapped_method ) queryset . iterator = _wrap_generator_with_readonly ( queryset . iterator )
wrap all methods that do database queries with a readonly connection .