[Zope-CMF] how to store a reference?

Doug Hellmann doug@hellfly.net
Wed, 23 Oct 2002 15:58:27 -0400


On Wednesday 23 October 2002 3:15 pm, Mark McEahern wrote:
> My hope is that this is really easy and my question merely reveals how
> shallow my understanding of Zope is...
>
> I have two portal types:  PressRelease and Contact.  A press release can
> have one or more contacts.  So in the press_release_edit_form.pt for
> PressRelease, I display the available contacts to choose from:
>
>   <select name="contacts" multiple="true"
>           tal:define="avail_contacts
> python:here.aq_parent.objectValue(['Contact'])">
>     <option tal:repeat="contact avail_contacts"
>             tal:attributes="value contact/getId; selected python:contact in
> here.contacts"
>             tal:content="contact/contact_name"/>
>   </select>
>
> What I'm scratching my head over is how, in press_release_edit.py, I *save*
> these contacts.  They'll get sent back in the RESPONSE as just plain
> strings representing the contact.getId(), right?  How do I inflate those
> into the Contact object before stuffing them in the press_release.contacts
> list?
>
> I can probably brute force this, but this seems like such a common thing, I
> have this gut feeling that I'm going to miss the obvious and simple
> solution.
>
> Any insights are appreciated!

You probably want to just store the name, and convert to the real object when 
you try to use it another script.  Otherwise you're going to end up with 
multiple copies of the Contact objects.

As far as the actual conversion, how about a Catalog lookup?

Doug