[Grok-dev] How to use auto-forms to quickly handle nested objects

Steve Schmechel steveschmechel at yahoo.com
Sun Mar 22 00:19:53 EDT 2009


If you have a "grok.Model based" object that contains one or more collections of other "grok.Model based" objects, is there are way to quickly represent this hierarchy using auto-forms?

I cannot find any examples of this nested structure in tutorials, how-to's, or example applications.  This would seem to be a natural layout for many object domains.  

Is this generally handled differently?  Is everything handled as "annotations"?  Is everything jammed in the main application "grok.Container" and then located as needed using separate indexes/catalogs?

Take, for example, the mammoth example in:
http://grok.zope.org/documentation/tutorial/work-with-forms

Mammoth(grok.Model) objects are stored in the MammothApplication(grok.Application, grok.Container) and auto-forms are used to view, add and edit mammoths.

If a caveman wanted to track how much food his mammoth was consuming, we might have a collection of "feedings" for a given mammoth.  Each "feeding" object would have attributes/fields for the "type of food" and the "weight".  For simplicity, both attributes could be just user-entered text but the feeding should be derived from grok.Model (not a list of string pairs or something like that).

It appears that zope.schema has a "Container" type and a "Dict" type.  
(grok.Container would map to Dict???)
Assuming we just want to be able to record the feedings and be able to view a simple listing of feedings for a given mammoth, what would be the quickest way to do this? 

Can the auto-forms generate an "add" button on the Mammoth auto-form that takes you to a "grok.AddForm" for a Feeding?  Can the auto-form simply generate a hyper-link when displaying the "Feedings" field (grok.Container), so that you can navigate to that object and render a view/template that lists the individual feedings?

I know all of this is rather basic and wouldn't make for a great user interface, but it would allow you to quickly prototype your content objects.

I believe the whole "custom widgets" and "multi-adapters" route is probably the right way to do this sort of thing.  But it is a lot for a newbie to get their head around and I haven't seen any simple examples applied in any tutorials.

Any advice is appreciated.  I will include what I learn in a tutorial that I am writing.  I really just need to be steered in the right direction.

Thanks,
Steve


      


More information about the Grok-dev mailing list