[Zope] Zope and Objects
Tue, 25 Mar 2003 15:01:53 +0100
Jeff Childers wrote:
> 1) Where are data object classes defined in Zope?
The ones you can select from the "Add..." menu.
> 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] ] ].
> 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?
You can do it inside Zope with ZClasses, but I'd recommend you to do it
outside of Zope in so called "python classes". This are located in
lib/python/Products or just /Products.
Start with the "BoringProduct" example and go from there.
Theres a some about this in the Zope Book too.
> 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?
You subclass them from a CatalogAware class, and call reindex each time
they have changed.
> 2) How do I instantiate and persist (through the session) a particular
> instance of the class from the ZODB (i.e. a certain customer)?
customer = CustomerClass()
You store it persistently by setting the new object as an attribute on
another persistent object. How you do this depends on your other
persistent object. You also need to subclass your class from
Persistance.Base. The most trivial example is:
folder[customer_name] = customer # where customer is the CustomerClass
# instance you created above
Yes, it is really that simple.
> I realize these are big questions.
Well, if you liked Zope before, you'll soon like it more, because with
Zope, this is small, simple questions. :)