[Zope3-Users] updating objects in ZODB

Max M maxm at mxm.dk
Fri Feb 10 05:26:08 EST 2006


Lorenzo Gil Sanchez wrote:

> Hi,
>
> I have a question about updating the objects in a ZODB. Suppose I 
> already have 100 objects of class A and then I modify class A adding a 
> new attribute. Then I craete a new object of the class A and now I 
> have two kind of instances of my class A, the old ones and the new one.
>
> How do I update the old objects and add the new attribute to them? I 
> can provide a default value for this attribute if that helps.  




You can just add the new variables as a class variable.

class SomeOldClass:

    newVar = ''

    ....



Or you can make a mixin class for compatibility. This can make your code 
a bit more readable.

class Compatibility:

    # added in ver. 1.1
    newVar = ''

class SomeOldClass(Compatibility):

    ...


Or you can use setter and getter methods.

class Compatibility:

    def getNewVar():
        return geatattr(self, newVar, '')


-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science



More information about the Zope3-users mailing list