Can I use SQLFORM for get id row (only read)?

47 views
Skip to first unread message

Константин Комков

unread,
Sep 10, 2019, 10:19:01 AM9/10/19
to web2py-users
Hello! I have SQLFORM:
db.tt_main.GROUP_ID.requires = IS_IN_DB(db((db.a_groups.id == db.tt_main.GROUP_ID) & (db.a_groups.INACTIVE == 0) & (db.a_groups.FO == 1)),db.a_groups.id,'%(NAME)s')
db
.tt_main.MODULE.requires = IS_IN_DB(db(db.tt_main.MODULE), db.tt_main.MODULE)
form
= SQLFORM(db.tt_main,fields=['MODULE','GROUP_ID'],labels = {'MODULE':T('Module'),'GROUP_ID':T('Name of group')},submit_button=T('Select timetable'))
if form.validate():
   
#don't work ↓
   
#form.vars.id = db.person.select(**dict(form.vars))
for that table of timetables:
db.define_table(
   
'tt_main',
   
Field('GROUP_ID','reference a_groups',unique=True),
   
Field('MODULE', 'integer',unique=True),
    migrate
=False
)
If I add readonly=True,record_id=True for SQLFORM None in Form on site, like on picture. I just want get id of timetable in user interface for create ability edit it.
1.png

Константин Комков

unread,
Sep 11, 2019, 3:04:16 AM9/11/19
to web2py-users
It's work:
if form.validate():
    form
.vars.id = db((db.tt_main.MODULE == form.vars.MODULE) & (db.tt_main.GROUP_ID == form.vars.GROUP_ID)).select(db.tt_main.id).first().id

Dave S

unread,
Sep 11, 2019, 4:41:56 AM9/11/19
to web2py-users
I'm glad you were able to find an answer.  I'm spoiled by having form.accepts()  set that value, but of course that doesn't work for read-only.

/dps

Reply all
Reply to author
Forward
0 new messages