def where_node_children(node):
    ''' Recursively visit all children of a where node, yielding each field in turn.
        - node: the node to visit
    '''
    todo = [node]
    get_field_name = ((lambda n: n.lhs.target.name) if django.VERSION >= (1, 7) else
                      (lambda n: n[0].field.name))
    while todo:
        node = todo.pop()
        for child in node.children:
            try:
                field_name = get_field_name(child)
            except (__HOLE__, AttributeError):
                pass
            else:
                yield child, field_name
            if isinstance(child, WhereNode):
                todo.append(child)

#===============================================================================
# Query manipulations
dataset/ETHPy150Open KristianOellegaard/django-hvad/hvad/query.py/where_node_children