tags:

views:

186

answers:

1

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 proble is when i select a year from dropdown the value of year coloumn is id of year not year value e.g:"if year 2009 has id =1 the value of year in db equal=1 not equal 2009" i dont know why?? could any one tell me the reason.

Thanks in advance

+1  A: 

Hi, 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.

RedGlyph
The years values is displayed correct into drop-down but the incorrect scenario is, it saved the id of the selected year not the year number (e,x: 2009)
Neveen
You mean in your field `year`? That's normal, you define your field as `db.All_years` which is a reference to another table, thus the id. That should not be an issue, to display it for example, you can use `rows = db(db.mytable.year == db.All_years.id).select(db.All_years.fromY, db.All_years.toY, ...)`.
RedGlyph
yes, you are alright thanks
Neveen