def to_refs(value):
from mongoframes.frames import Frame, SubFrame<EOL>if isinstance(value, Frame):<EOL><INDENT>return value._id<EOL><DEDENT>elif isinstance(value, SubFrame):<EOL><INDENT>return to_refs(value._document)<EOL><DEDENT>elif isinstance(value, (list, tuple)):<EOL><INDENT>return [to_refs(v) for v in value]<EOL><DEDENT>elif isinstance(value, dict):<EOL><INDENT>return {k: to_refs(v) for k, v in value.items()}<EOL><DEDENT>return value<EOL>
Convert all Frame instances within the given value to Ids