View data using dropdown form.

27 views
Skip to first unread message

Swayambodha Mohapatra

unread,
May 26, 2017, 9:36:29 AM5/26/17
to web2py-users
I am a novie in coding. Please help me out. 
How to create a drop down form that shows the user the data specific to a record?
For example, in this code I have the data stored for a number of cricket players. In this drop down list, I want to just show the data specific to the player chosen from the drop down menu. 
db.define_table ('Cricket',
Field('Name'),
Field('Age'),
Field('ODI_Runs'),
Field('ODI_Wickets')
)
db.Cricket.Name.requires = IS_NOT_EMPTY ()
db.Cricket.Age.requires = IS_INT_IN_RANGE (0,100)
db.Cricket.ODI_Runs.requires = IS_INT_IN_RANGE (0,20000)
db.Cricket.ODI_Wickets.requires = IS_INT_IN_RANGE (0,1000)
def index(): return dict(message="hello from view_data.py")
def view_data() :
form=SQLFORM.factory(Field('Name',requires=IS_IN_DB(db,'Cricket.Name')))
if form.accepted:
response.flash='Viewing Selected Data'
records=SQLTABLE(db().select(db.Cricket.ALL)) // This is the part where the problem lies. I don't know how to pass the 'Name' that has been selected.
return dict(form=form, record=records)
response.menu=[['View Player Data', False, URL(view_data)]]

Massimo Di Pierro

unread,
May 29, 2017, 7:09:21 PM5/29/17
to web2py-users
records=SQLTABLE(db(db.Cricket.Name == form.vars.Name).select(db.Cricket.ALL))
Reply all
Reply to author
Forward
0 new messages