def queryset_to_sql(queryset):
    """
    Transform a queryset into pretty sql that can be copy-pasted directly
    into pg-admin
    """
    import sqlparse
    from django.db import connection
    sql, sql_params = queryset.query.get_compiler(using=queryset.db).as_sql()
    with connection.cursor() as cur:
        query = cur.mogrify(sql, sql_params)
    query = sqlparse.format(query, reindent=True, keyword_case='upper')
    return query
