[Grok-dev] object relationships

Jeroen Michiel jmichiel at yahoo.com
Wed Jan 28 11:43:43 EST 2009



Martijn Faassen-2 wrote:
> 
> You'd need to write a new widget to select things 
> though (using zc.sourcefactory perhaps to provide a source to drop down 
> from).
> 
Alas, I'm too new to Grok to write my own widgets, I fear ;-) I'm just
getting around to using the existing ones...


Martijn Faassen-2 wrote:
> 
> I'm not sure whether the field supports the use of Choice here right 
> now, I'd need to do some experimenting there...
> 
I tried that with value_type=schema.Choice(source=TestSource()), but I got
an error for an unexpected 'value_type' parameter. It would be brilliant if
it would work like that, or something analogous.

What I'm trying now is something like this:

class ITestData(Interface):
    rel = relationfield.Relation(title=u'Relation')

class Add(grok.AddForm):
    grok.context(Interface)
    form_fields = grok.Fields(ITestData,
select=schema.Choice(title=u'Relation', source=TestSource())).omit('rel')

    @grok.action('Add')
    def Add(self, **data):
        print str(data)
        testdata = TestData()
        intids = component.getUtility(IIntIds)
        id = intids.getId(data['select'])
        print id
        data['rel'] = relationfield.RelationValue(id)
        self.applyData(testdata, data) 

So I replace the field by a normal choice field, and then afterwards,
replace it back by creating the relation myself (but it's still very crude,
and I don't know whether it'll work that way).
However, I get an error that the IIntIds can't be looked up. How do I
register it? Via install_requires, or ZCML, or something? Sorry for the
possible noob questions, but I have no prehistory of Zope whatsoever...
-- 
View this message in context: http://www.nabble.com/object-relationships-tp21706997p21709548.html
Sent from the Grok mailing list archive at Nabble.com.



More information about the Grok-dev mailing list