I am using SQLobject and still have not been able to find an elegant solution for updating a row in db or creating a new one if it does not exist.
I am currently using the following somewhat convoluted code:
args = dict(artnr=artnr, name=name, hersteller='?', hersteller_name='?')
if cs.datamart.ArtNrNameHersteller.selectBy(artnr=artnr).count():
row = cs.datamart.ArtNrNameHersteller.selectBy(artnr=artnr)[0]
row.set(**args)
else:
cs.datamart.ArtNrNameHersteller(**args)
Obviously, this is far from insane, strong, elegant or fast. What is the correct way (TM) for this?
source
share