Hey
i want to maintain a list of user objects in a class and also a dirty
variable
so when i do
z=User()
z.name='new name'
z.save()
i want it to use the dirty variable to save only the changed items in the
class variables to the db
so the class i have is this
class User(object):
"""user object
"""
def __init__(self, id):
self.userid = id
self.id=id
if 1:
self.userrow=db.query("select * from users where
id=$id",vars=locals())
if self.userrow:self.userrow=self.userrow[0]
for k in self.userrow.keys():
setattr(self,k,self.userrow[k])
self.dirty = {}
return None
def __setattr__(self, key, value):
object.__setattr__(self,key,value)
if hasattr(self,'dirty'):
if key in self.userrow.keys():#if key!='dirty':
self.dirty[key]=value
def save(self):
''' using dirty method from web.Storage -'''
if self.dirty:
db.update('users', self.id, **self.dirty)
self.dirty = {}
return self
else:
return None
Can we do this using class property function or is there a cleaner way to do
this
thanks a lot
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---