I'm trying to make a query using the relation catalog with from_attribute and to_id as the parameters.
I have a content type called Contract, which has a RelationChoice field called 'project'.
from plone.app.vocabularies.catalog import CatalogSource
from z3c.relationfield.schema import RelationChoice
class IContract(model.Schema):
project = RelationChoice(title=u"Project",
description=u"Set in events",
source=CatalogSource(portal_type=['Project',]),
required=False
)
and I have a content type called Project, which is tied to the Contract.
from zope.intid.interfaces import IIntIds
from zc.relation.interfaces import ICatalog
from zope.component import getUtility
class IProject(model.Schema):
...
@implementer(IProject)
class Project(Item):
def get_contract(self):
intids = getUtility(IIntIds)
catalog = getUtility(ICatalog)
from_attribute = 'project'
to_id = intids.getId(self)
query={'from_attribute':from_attribute,
'to_id':to_id
}
relations = catalog.findRelations(query)
objs = [i.to_object for i in relations]
print(objs) #Empty list
if objs:
return objs[0]
else:
return None
In my view template for, I have
<div tal:define="contract python:context.get_contract()">
</div>
When I do this, the print statement in get_contract prints an empty list.
What am I doing wrong? Is intids.getId(self) not getting the right int id or is 'project' not being added? Or perhaps I'm getting the to/from backwards?