def _Q_to_filter(self, q):
default_filter = ANDFilter<EOL>if q.connector == "<STR_LIT>":<EOL><INDENT>default_filter = ORFilter<EOL><DEDENT>filters = []<EOL>for child in q.children:<EOL><INDENT>if isinstance(child, Q):<EOL><INDENT>if child.children:<EOL><INDENT>filters.append(self._Q_to_filter(child))<EOL><DEDENT><DEDENT>elif isinstance(child, tuple):<EOL><INDENT>field, value = child<EOL>filters.append(self._build_inner_filter(field, value))<EOL><DEDENT><DEDENT>if len(filters) == <NUM_LIT:1>:<EOL><INDENT>filter = filters[<NUM_LIT:0>]<EOL>if q.negated:<EOL><INDENT>return NotFilter(filter)<EOL><DEDENT>return filter<EOL><DEDENT>if q.negated:<EOL><INDENT>return NotFilter(default_filter(filters))<EOL><DEDENT>return default_filter(filters)<EOL>
Convert a Q object to filter
:param q: a Q Object
:return: a filter object