[Zope3-Users] How to persist an attribute of list type
Paul Winkler
pw_lists at slinkp.com
Fri Nov 30 21:49:13 EST 2007
On Sat, Dec 01, 2007 at 02:34:49AM +0800, Yuan HOng wrote:
> Hi,
>
> It seems that I can not get list attribute of an persistent object
> changed. I have the following class, which has a list as one of its
> attributes:
>
> class Cart(Persistent):
> items = []
> amount = 0
I hope that's not your actual code. Note here that items is a mutable
class attribute, so if you do this:
cart = Cart()
cart.items.append('foo')
... you've just mutated the default list for all instances. Is that
really what you want? ZODB persistence can only store instance
attributes, not class attributes.
But that's irrelevant to the rest of your examples, because you
re-assigned cart.items, which should work. I don't know what's wrong
there.
--
Paul Winkler
http://www.slinkp.com
More information about the Zope3-users
mailing list