diff --git a/IPython/html/static/widgets/js/widget.js b/IPython/html/static/widgets/js/widget.js
index 92bfcbe..55b954a 100644
--- a/IPython/html/static/widgets/js/widget.js
+++ b/IPython/html/static/widgets/js/widget.js
@@ -213,7 +213,7 @@ define(["widgets/js/manager",
var that = this;
var packed;
if (value instanceof Backbone.Model) {
- return value.id;
+ return "IPY_MODEL_" + value.id;
} else if ($.isArray(value)) {
packed = [];
@@ -252,13 +252,15 @@ define(["widgets/js/manager",
});
return unpacked;
+ } else if (typeof value === 'string' && value.slice(0,10) === "IPY_MODEL_") {
+ var model = this.widget_manager.get_model(value.slice(10, value.length));
+ if (model) {
+ return model;
+ } else {
+ return value;
+ }
} else {
- var model = this.widget_manager.get_model(value);
- if (model) {
- return model;
- } else {
return value;
- }
}
},
diff --git a/IPython/html/widgets/widget.py b/IPython/html/widgets/widget.py
index 72c9c23..2abada0 100644
--- a/IPython/html/widgets/widget.py
+++ b/IPython/html/widgets/widget.py
@@ -322,7 +322,7 @@ class Widget(LoggingConfigurable):
elif isinstance(x, (list, tuple)):
return [self._serialize_trait(v) for v in x]
elif isinstance(x, Widget):
- return x.model_id
+ return "IPY_MODEL_" + x.model_id
else:
return x # Value must be JSON-able
@@ -335,7 +335,7 @@ class Widget(LoggingConfigurable):
return {k: self._unserialize_trait(v) for k, v in x.items()}
elif isinstance(x, (list, tuple)):
return [self._unserialize_trait(v) for v in x]
- elif isinstance(x, string_types) and x in Widget.widgets:
+ elif isinstance(x, string_types) and x.startswith('IPY_MODEL_') and x[10:] in Widget.widgets:
# we want to support having child widgets at any level in a hierarchy
# trusting that a widget UUID will not appear out in the wild
return Widget.widgets[x]