From: Andreas K. <an...@ko...> - 2005-09-12 08:41:04
|
Am Samstag, den 10.09.2005, 22:47 +0400 schrieb Oleg Broytmann: > On Sat, Sep 10, 2005 at 09:29:17AM +0200, Andreas Kostyrka wrote: > > Am Freitag, den 09.09.2005, 17:05 +0400 schrieb Oleg Broytmann: > > > On Fri, Sep 09, 2005 at 02:53:05PM +0200, Andreas Kostyrka wrote: > > > > class Worktime(SQLObject): > > > > customer =3D ForeignKey("customer", default=3DWHATDOIPUTHERE) > > > > task =3D ForeignKey("task") > > >=20 > > > > Now, a _set_customer setter doesn't work, because it needs the > > > > corresponding .task value > > >=20 > > > And what? > > Well, somehow a default value derived from another column would make > > much sense. Not only in this case but others too. >=20 > 1. I still do not understand why your _set_customer doesn't work, and > what the .tash has to do with it. > 2. Can you explain your wish in terms of SQL? Can you write a > CREATE TABLE clause declaring a default value for a column that depends o= n > another column? Probably not. I can write a __init__ method. The idea is trivial, but probably not 100% correct in the the sense of database normalization. There are basically two cases that are modeled by this: * you work some time for a customer, BUT you do not know against which task it will be booked at the end. * And afterwards it can be used to speed up lookups for times worked for a certain customer. >=20 > > > > and it seems that _set_customer doesn't get > > > > called by Worktime(...) > > >=20 > > > It must get called. What version of SQLObject? > > probably r915. >=20 > Fresh enough. Are you sure _set_customer doesn't get called? I'll try a smaller testcase to verify that it's not something else. ;) Ok, I've tested against 0.6 and r915. from sqlobject import * import os os.unlink("/tmp/stest") __connection__ =3D dbconnection.connectionForURI("sqlite:///tmp/stest") class Customer(SQLObject): name =3D StringCol() class Task(SQLObject): name =3D StringCol() class Test(SQLObject): customer =3D ForeignKey('Customer') task =3D ForeignKey('Task') def _set_customer(self, val): print "VAL", val self._SO_set_customer(val) Customer.createTable(ifNotExists=3DTrue) Task.createTable(ifNotExists=3DTrue) Test.createTable(ifNotExists=3DTrue) cust =3D Customer(name=3D"cust1") task =3D Task(name=3D"Task1") Test(customer=3Dcust, task=3Dtask) My understanding is, that it should print something, right? It does not :( Andreas |