[Grok-dev] object relationships

Martijn Faassen faassen at startifact.com
Tue Feb 10 14:58:24 EST 2009

Hey Jeroen,

Sorry for the delay in getting back to this.

I've now extended z3c.relationfield and z3c.relationfieldui with support 
for a ``RelationChoice`` field. This works much like a normal 
schema.Choice field, but you should pass a 
``z3c.relationfieldui.RelationSourceFactory`` into it. In the source 
factory you should implement a ``getTargets`` method (and only that is 
needed) that returns a list of potential targets, for instance one 
obtained through a catalog query or through a container.values().

It will automatically start using a widget that presents the options as 
a drop-down lists. You may want to override 'getTitle()' too on your 
source factory to let it display a nicer name for the values; be aware 
you get as value there a RelationValue object, but with .to_object you 
can get to the option it's pointing at, to, say, obtain *its* title.

Let me know how that works for you.



More information about the Grok-dev mailing list