@classmethod<EOL><INDENT>def traverse_qs(cls, obj_iter, path):<DEDENT>
ret_val = []<EOL>if hasattr(obj_iter, '<STR_LIT:all>'):<EOL><INDENT>obj_iter = obj_iter.all()<EOL><DEDENT>try:<EOL><INDENT>iter(obj_iter)<EOL><DEDENT>except TypeError:<EOL><INDENT>obj_iter = [obj_iter]<EOL><DEDENT>for obj in obj_iter:<EOL><INDENT>rel_objs = []<EOL>for part in path:<EOL><INDENT>if not part:<EOL><INDENT>continue<EOL><DEDENT>try:<EOL><INDENT>related = getattr(obj, part[<NUM_LIT:0>])<EOL><DEDENT>except ObjectDoesNotExist:<EOL><INDENT>continue<EOL><DEDENT>if related is not None:<EOL><INDENT>rel_objs.extend(cls.traverse_qs(related, [part[<NUM_LIT:1>:]]))<EOL><DEDENT><DEDENT>ret_val.append((obj, rel_objs))<EOL><DEDENT>return ret_val<EOL>
Helper method that returns a list containing a list of the objects in the
obj_iter. Then for each object in the obj_iter, the path will be
recursively travelled and the found objects are added to the return value.