Re: [SQLObject] a couple of questions: field inheritance and update/instert distinction
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Diez B. R. <die...@ar...> - 2006-11-28 17:41:58
|
On Monday 27 November 2006 19:47, Oleg Broytmann wrote: > On Mon, Nov 27, 2006 at 07:04:33PM +0100, Diez B. Roggisch wrote: > > class User(SQLObjec): > > ... > > > > def _init(self, *args, **kwargs): > > if <the_table_row_is_created>: > > co_object =3D CoObject(userID=3Dself.id) > > return super(User, self)._init(*args, **kwargs) > > > > This will ensure there is a CoObject whenever there is a User. > > _init() is called during creation, so you can be sure the row has not > been inserted into the DB yet, and there is no is. You need to change the > order of operations: > > def _init(self, *args, **kwargs): > super(User, self)._init(*args, **kwargs) # Perform INSERT and > get the id co_object =3D CoObject(userID=3Dself.id) Ok, I tried your suggestion - this is the code: class Guide(User): def _init(self, *args, **kwargs): super(Guide, self)._init(*args, **kwargs) # Perform INSERT and get = the=20 id user_name =3D self.user_name name =3D I18NText() name['en'] =3D user_name name['de'] =3D user_name description =3D I18NText() description['en'] =3D user_name description['de'] =3D user_name =20 my_bookable =3D GuideBookable(handle=3Duser_name, name=3Dname,=20 description=3Ddescription, proportional_price=3Ddecimal.Decimal('0= '), fixed_price=3Ddecimal.Decimal('0'), quantity=3D1, bookable_quantity=3D1, customer_visible=3DFalse, guideID =3D self.id ) Works fine for the first time. However, if I do for example Guide.get(<the_id>) I get an error like this: model.py in _init(self, *args, **kwargs) 383 def _init(self, *args, **kwargs): 384 super(Guide, self)._init(*args, **kwargs) # Perform INSERT = and=20 get the id =2D-> 385 user_name =3D self.user_name 386 name =3D I18NText() 387 name['en'] =3D user_name So - it seem _init is called on reloading the object as well, not only on=20 creation time. Any suggestions? =2D-=20 >> Diez B. Roggisch >> Developer T +49 (30) 443 50 99 - 27 =46 +49 (30) 443 50 99 - 99 M +49 (179) 11 75 303 E die...@ar... >> artnology GmbH A Milastra=DFe 4 / D-10437 Berlin T +49 (30) 443 50 99 - 0 =46 +49 (30) 443 50 99 - 99 E in...@ar... I http://www.artnology.com |