开发者

web2py - require selected dropdown values validate from db

开发者 https://www.devze.com 2022-12-09 07:08 出处:网络
i have a table member that include SQLField(\"year\", db.All_years) and All_years table as the following:

i have a table member that include SQLField("year", db.All_years)

and All_years table as the following:

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

and constrains are :

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

The problem is when I select a year from dropdown the value of y开发者_开发技巧ear column is the id of year, not the year value e.g: if year 2009 has db id=1 the value of year in db equal=1 not equal 2009.

I don't understand why.


I see your project is progressing well!

The validator is IS_IN_DB(dbset, field, label). So you should try:

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

to have a correct label in your drop-down list.

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

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

that will display, for example, "1980 to 1985", and so on.

0

精彩评论

暂无评论...
验证码 换一张
取 消