[Zope] Zope and Objects
Mark McEahern
marklists@mceahern.com
Tue, 25 Mar 2003 08:09:22 -0600
[Jeff Childers]
> I'm starting to get the "big picture" but I'm still a little fuzzy
> on the details, particularly about objects and the ZODB. I'm hoping
> that someone can give me some brief pointers to where the answers
> the these questions lie. I have read a *bunch* of Zope doc and I'm
> pretty handy with Python.
>
> 1) Where are data object classes defined in Zope?
I'm fairly new to Zope, although I've written some Zope Products. My
sense is that there are two answers to your question:
* ZClasses
* Products
and that the best bet in the long-run, especially if you feel
comfortable with Python, is to skip ZClasses altogether and focus on
grokking Products.
> I get the persistent object thing. Very cool. So let's say I want to
> write a billing system. I have customer objects, invoice objects,
> and payment objects. [ Customer [ Invoices [Payments] ] ].
My guess is that you'd write a Product, BillingSystem. The
BillingSystem Product would include a variety of classes:
* A top-level container; e.g., Billing
* Customer
* Invoice
* Payment
Only the top-level container would be addable to other Zope containers
(folderish objects). Once you adding an instance of Billing, it would
have a slightly customized manage_main (I'm probably misspelling
that). From Billing's manage_main, you could add Customers. From a
Customer's management screens, you could add Invoices. And so on.
> a) Where do I put the code that defines each custom class? Scripts
> seem to be for def-functions. Do I have to put this outside Zope?
Yes, that's your best bet. The common wisdom seems to be: Write this
as if it's just Python, then add a light wrapper for Zope. Of course,
the devil can sometimes be in the details.
> b) Do I use ZCatalogs to 'index' my objects so I can query them
> similar to SQL? If so, how/where do I add my custom classes to the
> ZCatalog?
Good question.
> 2) How do I instantiate and persist (through the session) a
> particular instance of the class from the ZODB (i.e. a certain
> customer)?
The thing about PersistentObject is that you don't really have to do
anything for it to persist aside from instantiating it in Zope. Isn't
that cool?
> I realize these are big questions. Any pointer toward answers, even
> which documentation I should be reading, would be helpful and
> greatly appreciated.
I think the short answer is that you want to investigate Products.
I'm hoping someone more knowledgeable about the specifics follows up.
Cheers,
// m
-