The second argument of IS_IN_DB should be the key to the reference.
And the third should be a format string to represent that key.

So your models should look something like
db.define_table('t_itemtypes',
    Field('f_itemtypedesc_string', 'string'),
    )
db.define_table('t_items',
    Field('f_itemname_string', type='string', notnull=True, label=T(
'ItemName')),
    Field('f_itemtype', type='reference t_itemtypes', label=T('ItemType')),
          requires=IS_IN_DB(db, 't_itemtypes.id', 
'%(f_itemtypedesc_string)s')
    )



On Saturday, October 24, 2015 at 8:31:27 PM UTC-4, Bill Lugg wrote:
>
> I am vary new to Web2py and am very impressed with what I see so far.  I 
> come from a MS Access background and am looking for an easy way to develop 
> small db applications in similar fashion and offering some of the same 
> features that are offered in Access, but without the proprietary chains 
> that MS imposes.
>
> I've been experimenting with a simple inventory app and I have a situation 
> where I have some lookup tables that I want to reference in my main item 
> form.  In my first attempt, the lookup table contains an integer item type 
> and a string item type description.  I'd like the main form to display the 
> descriptions, but store either a link or a copy of the integer item type in 
> the items table (at this point I'm not too picky).  FWIW, I used the wizard 
> to generat the application to start.
>
> Here's the code as I modified it to display the item type description in 
> the items form:
>
> db.define_table('t_items',
>     Field('f_itemname_string', type='string', notnull=True,
>           label=T('Itemname String')),
>     Field('f_itemtype', type='reference t_itemtypes',
>           requires=IS_IN_DB(db, 't_itemtypes.f_itemtype', 
> 't_itemtypes.f_itemtypedesc_string'),
>           label=T('Itemtype')),
>
>
> This works, but when I insert a record I get the following error:
> e IntegrityError('FOREIGN KEY constraint failed',)
>
> Looking at the arguments up the stack a bit, it appears to be trying to 
> put an integer in for the item type so I'm a little stumped as to what 
> might be wrong.  I wonder if someone might be able to point me in the right 
> direction as I will want to do this with a couple of other fields as well.
>
> In addition, I have a couple of integer fields that I want to make a fixed 
> list from 1 to 4, inclusive.  I was going to use the requires=IS_IN_SET 
> construct for this; am I headed in the right direction?
>
> Thanks for the help with this.
>
> Bill Lugg
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to