[SQLObject] Magic attribute and object ID problem
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Emmanuel G. <ega...@le...> - 2008-12-16 02:46:53
|
Hello, I am trying to use magic attributes at the time of object creation. Unfortunately self.id is not available until after the object is created. Attempting to set a magic attribute at creation time results in the exception: AttributeError: 'Resource' object has no attribute 'id' (with attribute 'details') I am using the latest SQLObject code from subversion (SQLObject-0.11dev_r3720). Test code: ################################################## from sqlobject import * sqlhub.processConnection = connectionForURI('postgres://test@localhost/test') class Resource(SQLObject): name = StringCol() def _set_details(self, value): print "My id is %d" % self.id Resource.dropTable(ifExists=True) Resource.createTable() # Works. #a = Resource(name = 'test1') #a.details = 'fruit' # Does NOT work. b = Resource(name = 'test2', details = 'chair') ################################################## Regards, Emmanuel |