diff --git a/src/wuttaweb/forms/schema.py b/src/wuttaweb/forms/schema.py index b3f0105..77e443e 100644 --- a/src/wuttaweb/forms/schema.py +++ b/src/wuttaweb/forms/schema.py @@ -334,8 +334,21 @@ class ObjectRef(colander.SchemaType): # nb. keep a ref to this for later use node.model_instance = appstruct - # serialize to uuid - return appstruct.uuid.hex + # serialize to PK as string + return self.serialize_object(appstruct) + + def serialize_object(self, obj): + """ + Serialize the given object to its primary key as string. + + Default logic assumes the object has a UUID; subclass can + override as needed. + + :param obj: Object reference for the node. + + :returns: Object primary key as string. + """ + return obj.uuid.hex def deserialize(self, node, cstruct): """ """ @@ -417,7 +430,7 @@ class ObjectRef(colander.SchemaType): if 'values' not in kwargs: query = self.get_query() objects = query.all() - values = [(obj.uuid.hex, str(obj)) + values = [(self.serialize_object(obj), str(obj)) for obj in objects] if self.empty_option: values.insert(0, self.empty_option)