Changes between Version 2 and Version 3 of IS_ONE_OF


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

--

Legend:

Unmodified
Added
Removed
Modified
  • IS_ONE_OF

    v2 v3  
    33The IS_ONE_OF() validator is a custom version of web2py's IS_IN_DB() for foreign key lookups in a key table. In forms, the respective field will be rendered as a drop-down field.
    44
    5 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. Furthermore, it is possible to filter the key records by a type field (which should be int) for certain options.
     5Other 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.
     6
     7Furthermore, it is possible to filter the key records by a type field (which should be int) for certain options.
    68
    79Usage:
     
    1113  - ''keyfield'' = Name of the key field
    1214  - ''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
     15    - string template, e.g. {{{"%(first_name)s %(last_name)s"}}}
     16    - list or tuple of field names, e.g. {{{('first_name', 'last_name')}}}
     17    - function or lambda, e.g. {{{lambda r: "%(first_name)s %(last_name)s" % dict(r)}}}
     18  - filterby=''"fieldname"'' = the type field (int) to filter for
    1719  - filter_opts=''"options"'' = a list or tuple of allowed values for the filterby-field
    1820
     
    2830
    2931db[table].pr_pe_id.requires = IS_NULL_OR(IS_ONE_OF(db,
    30     'pr_pentity.id',
    31     shn_pentity_represent,
    32     filterby='opt_pr_pentity_class',
    33     filter_opts=(1,)
     32    'pr_pentity.id',                          # key table pr_pentity, key field id
     33    shn_pentity_represent,                    # function to represent a pr_pentity entry as string
     34    filterby='opt_pr_pentity_class',          # type field in the pr_pentity table
     35    filter_opts=(1,)                          # select only entries with opt_pr_pentity_class in (1,) (select only persons)
    3436    ))
    3537}}}