def prepare_rows_as_nested_dicts(query, nested_dict_column_names):
 all_dicts = []
 for row in query.select_related():
  row_dict = row.get_object_dict()
  for column in nested_dict_column_names:
   if (row_dict[column] is not None):
    row_dict[column] = getattr(row, column).get_object_dict()
  all_dicts.append(row_dict)
 return prepare_for_serialization(all_dicts)

def prepare_rows_as_nested_dicts ( query , nested_dict_column_names ) : all_dicts = [ ] for row in query . select_related ( ) : row_dict = row . get_object_dict ( ) for column in nested_dict_column_names : if ( row_dict [ column ] is not None ) : row_dict [ column ] = getattr ( row , column ) . get_object_dict ( ) all_dicts . append ( row_dict ) return prepare_for_serialization ( all_dicts )
prepare a django query to be returned via rpc as a sequence of nested dictionaries .