fix: add serialize_object()
method for ObjectRef
schema node
so we can use this node type for non-wutta mapped class, with non-uuid primary key
This commit is contained in:
parent
3041e01184
commit
e3c432aa37
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue