[Grok-dev] model not getting persisted
kevin at bud.ca
Fri Mar 23 18:07:49 EDT 2007
> Ok, I understand this. But how is the zope3 code working then? I've
> class X(Persistent):
> a = u''
> b = u''
> a couple of times. How come the class attributes gets persisted here?
Those class attributes do not get persisted. They are just there as
defaults, so that you don't need to initialize them in the
constructor. With a class like the one above you can then write code
>>> obj = X()
>>> obj.a # instance attribute does not yet exist, so falls back to
>>> obj.a = u'Hello ZODB' # sets an instance attribute
>>> obj.__class__.a # class attribute is still available, it's now
just 'shadowed' by an instance attribute
This bit of documentation explains class vs instance attributes well:
More information about the Grok-dev