[Zope3-Users] How to persist an attribute of list type

Thierry Florac tflorac at ulthar.net
Fri Nov 30 16:00:39 EST 2007


Le samedi 01 décembre 2007 à 02:34 +0800, Yuan HOng a écrit :
> 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
> 
> In the debug console, I find that only with direct attribute
> assignment can I change the persisted attribute value. If I use
> items.append to modify the list, even after I set the _p_changed
> attribute of the cart object to True and commit, the persisted version
> won't change.
> 
> I also tried to use PersistentList as the type of the 'items'
> attribute. It doesn't work either with append.
> 
> What could be missing? I am using Zope 3.4.

You just have to use persistent lists :

  from persistent.list import PersistentList
  
  class Cart(Persistent):
    items = PersistentList()
    amount = 0

Persistent list are then handled as normal Python lists.

  Thierry


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.



More information about the Zope3-users mailing list