[Zope-CMF] Add properties to already existing content types
Dieter Maurer
dieter@handshake.de
Wed, 18 Jun 2003 20:52:43 +0200
Rainer Thaden wrote at 2003-6-17 18:22 +0200:
> Hi,
>
> i had to add some properties to a file system based class which
> already had some instances in the ZODB.
> I did it like this:
> I defined a function do_update in the class and called the method on
> all instances.
> Here's the code:
>
> def do_update(self):
> id = self.id
>
> container = self.aq_parent
> ob = self
>
> ob.__dict__ = self.__dict__
> ob.__dict__['property1']=''
> ob.__dict__['property2']=''
>
> container.manage_delObjects(ids=[id])
> container._setObject(id, ob)
This is really funny code:
The following should be almost equivalent:
def do_update(self):
self.property1= ''
self.property2= ''
"manage_delObjects" will call "manage_beforeDelete"
and "_setObject" "manage_afterAdd". If they do something
essential for you (e.g. indexing), call them explicitly.
> The problem is that the new properties are tuples by default. When i
> debug in the edit method of the class and assign
>
> property1='bla'
>
> then i get property1=('bla') at the first time.
> When i assign it a second time i get the correct result.
There is probably a trailing "," somewhere.
The code you show above will not assign a tuple.
Dieter