Web2py - Requires selected dropdown values ​​to be validated with db

I have a table element that includes SQLField("year", db.All_years)

and All_years:

db.define_table("All_years",
  SQLField("fromY","integer"),
  SQLField("toY","integer")
  )

      

and restrictions:

db.member.year.requires = IS_IN_DB(db, 'All_years.id','All_years.fromY')

      

The problem is that when I select the year from the dropdown, the year column value is the year ID and not the year value, for example: if the year 2009 has db id = 1, the year value in db is = 1 is not 2009.

I do not understand why.

+2


source to share


1 answer


I can see that your project is going well!

Validator IS_IN_DB(dbset, field, label)

. Therefore, you should try:

db.member.year.requires = IS_IN_DB(db, 'All_years.id', '%(fromY)d')

      

to have the correct shortcut in the dropdown.



Now, from your table, it looks like you would rather choose an interval rather than just the starting year, in which case you can use this:

db.member.year.requires = IS_IN_DB(db, 'All_years.id', '%(fromY)d to %(toY)d')

      

which will be displayed for example from 1980 to 1985 etc.

+2


source







All Articles