I have the following tables defined and want to make sure that when I
use crud.create(db.firmstrat) I stop duplicate strategies for the same
firm. What I have below works when firmstrat.firm_id is writable, but
not when writable=False. It looks like the request.vars.firm_id =
none when the field isn't writable for the crud form. Is there
another way to access the information? Other thing I have tried that
work are request.args(0) but I'm worried this may be an issue later if
I'm trying to write to the table when args(0) isn't the firm_id.
def show():
this_firm = db.firm(request.args(0)) or redirect(URL('index'))
db.firmstrat.firm_id.default = this_firm.id
form = crud.create(db.firmstrat)
strats = db(db.firmstrat.firm_id==this_firm.id).select()
return dict(strats=strats, firm=this_firm, form=form)
db.define_table('firm',
Field('name', unique=True, required=True))
db.define_table('lkfirmstrat',
Field('name', unique=True))
db.define_table('firmstrat',
Field('firm_id', db.firm, readable=False, writable=False),
Field('strat_id',db.lkfirmstrat))
check = db(db.firmstrat.firm_id==request.vars.firm_id)
db.firmstrat.strat_id.requires = IS_IN_DB(db, db.lkfirmstrat.id, '%
(name)s',
_and=IS_NOT_IN_DB(check,
'firmstrat.strat_id'))
Thanks,
Sam