[Grok-dev] Add forms - one object type to multiple object types
darryl at darrylcousins.net.nz
Sat Mar 10 18:54:28 EST 2007
On Sun, 2007-03-11 at 12:45 +1300, Darryl Cousins wrote:
> I'm trying out a simple site type app with grok.
> I've 3 content types: Site, Section and Page. Add form for page begins::
> class Add(grok.AddForm):
> So now I can add pages to Sites. But I want also to add them to
> Sections. So the Add class needs a different context:
> It seems that I need to make a new add class in order to do so, one for
> Site and the other for Section.
> Using zcml I would have been able to register the add class for both
> Sites and Sections. Here (as I see from my low stand point) it seems not
> so straight forward.
> Kind regards,
Actually it wasn't so bad as I thought. I can re-use the grok.name
(things start falling into place).
So having the 2 separate add classes works like this:
form_fields = grok.Fields(
form_fields += grok.AutoFields(Page)
def add(self, id, **data):
new = Page(**data)
self.context[id] = new
def cancel(self, **data):
More information about the Grok-dev