Replaces (lookup, value) children of Q with equivalent WhereNode objects.

    This is a pre-prep of our Q object, ready for later rendering into SQL.
    Modifies in place, no need to return.

    (We could do this in render_q, but then we'd have to pass the Query object
    from ConditionalAggregate down into SQLConditionalAggregate, which Django
    avoids to do in their API so we try and follow their lead here)

def transform_q(q, query):
    """
    Replaces (lookup, value) children of Q with equivalent WhereNode objects.

    This is a pre-prep of our Q object, ready for later rendering into SQL.
    Modifies in place, no need to return.

    (We could do this in render_q, but then we'd have to pass the Query object
    from ConditionalAggregate down into SQLConditionalAggregate, which Django
    avoids to do in their API so we try and follow their lead here)
    """
    for i, child in enumerate(q.children):
        if isinstance(child, Q):
            transform_q(child, query)
        else:
            # child is (lookup, value) tuple
            where_node = query.build_filter(child)
            q.children[i] = where_node