Changes between Initial Version and Version 1 of IS_ONE_OF


Ignore:
Timestamp:
08/23/09 12:51:03 (12 years ago)
Author:
Dominic König
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • IS_ONE_OF

    v1 v1  
     1= IS_ONE_OF Validator =
     2
     3The IS_ONE_OF() validator is a custom version of web2py's IS_IN_DB() for foreign key lookups in a key table. Other than IS_IN_DB, the IS_ONE_OF validator is deletion status sensitive, i.e. records in the key table that are flagged as 'deleted' will be ignored.
     4
     5Furthermore, it is possible to filter the key records by a type field (which should be int) for certain options
     6
     7Usage:
     8  db.table.field.requires = IS_NULL_OR(IS_ONE_OF(db, ''"keytable.keyfield"'', ''represent'', filterby=''"fieldname"'', filter_opts=''options''))
     9
     10  - ''keytable'' = Name of the key table
     11  - ''keyfield'' = Name of the key field
     12  - ''represent'' = how to build the option label (in drop-downs in forms) from the key entry, one of the following:
     13    - string template, e.g. "%(first_name)s %(last_name)s"
     14    - list of names of fields, e.g. ('first_name', 'last_name')
     15    - function or lambda, e.g. lambda r: "%(first_name)s %(last_name)s" % dict(r)
     16  - filterby=''"fieldname"'' = the type field (and int-field) to filter for
     17  - filter_opts=''"options"'' = a list or tuple of allowed values for the filterby-field
     18
     19  If filterby is specified, the drop-down fields get sorted by this field.
     20
     21Example:
     22{{{
     23...
     24db.Field('pr_pe_id', db.pr_pentity),
     25...
     26
     27db[table].pr_pe_id.requires = IS_NULL_OR(IS_ONE_OF(db,
     28    'pr_pentity.id',
     29    shn_pentity_represent,
     30    filterby='opt_pr_pentity_class',
     31    filter_opts=(1,)
     32    ))
     33}}}