문제

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 year 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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top