'Convert a Q object to filter
:param q: a Q Object
:return: a filter object'

def _Q_to_filter(self, q):

    default_filter = ANDFilter
    if (q.connector == 'OR'):
        default_filter = ORFilter
    filters = []
    for child in q.children:
        if isinstance(child, Q):
            if child.children:
                filters.append(self._Q_to_filter(child))
        elif isinstance(child, tuple):
            (field, value) = child
            filters.append(self._build_inner_filter(field, value))
    if (len(filters) == 1):
        filter = filters[0]
        if q.negated:
            return NotFilter(filter)
        return filter
    if q.negated:
        return NotFilter(default_filter(filters))
    return default_filter(filters)
