Do not sure crud. It is old, to be deprected, less flexible than SQLFORM. Do this:
form = SQLFORM(db.table, record_id) form.process(dbio=False) if form.accepted: if form.deleted: # to be deleted because dbio=False count = db(db.table3.field2t3 == form.record_id).count() if count: session.flash = T('The record you try to delete is still referenced by other records and can\'t be deleted') redirect(URL(c='default', f='create_update', args=request.args(0))) else: form.record.delete() else: form.record.update_record(**form.post_vars) On Wednesday, 12 December 2012 11:37:26 UTC-6, Richard wrote: > > Ok, I understand, but I don't want the record to be deleted, so SET TO > NULL not a solution. > > Now I try what I was trying to avoid : > > def ondelete_func2(form): > count = 0 > count += db(db.table3.field2t3 == request.args(1)).count() > if count > 0: > pass > else: > session.flash = T('The record you try to delete is still > referenced by other records and can\'t be deleted') > redirect(URL(c='default', f='create_update', args=request.args(0))) > > I want to look into table3 if a id of table2 is still referenced. > > I know that I don't need count+= it is like that because in my own app > there is not only one table3 there is 30+ tables that are referencing id of > table2 and that why I would avoid using query to be informed about that. > > Now what I don't know how to do is to prevent the crud.update() deletion > to occur in case of count > 0... > > Help is appreciate. > > Richard > > On Wed, Dec 12, 2012 at 12:29 PM, Massimo Di Pierro > <massimo....@gmail.com<javascript:> > > wrote: > >> add it because web2py does not do migration when ondelete changes. You >> have to delete your database, you .tables and start again. > > > --