def do_filter(qs, keywords, exclude=False):
and_q = Q()<EOL>for keyword, value in iteritems(keywords):<EOL><INDENT>try:<EOL><INDENT>values = value.split("<STR_LIT:U+002C>")<EOL>if len(values) > <NUM_LIT:0>:<EOL><INDENT>or_q = Q()<EOL>for value in values:<EOL><INDENT>or_q |= Q(**{keyword: value})<EOL><DEDENT>and_q &= or_q<EOL><DEDENT><DEDENT>except AttributeError:<EOL><INDENT>and_q &= Q(**{keyword: value})<EOL><DEDENT><DEDENT>if exclude:<EOL><INDENT>qs = qs.exclude(and_q)<EOL><DEDENT>else:<EOL><INDENT>qs = qs.filter(and_q)<EOL><DEDENT>return qs<EOL>
Filter queryset based on keywords.
Support for multiple-selected parent values.