Changes between Version 2 and Version 3 of IS_ONE_OF
- Timestamp:
- 08/23/09 13:09:55 (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
IS_ONE_OF
v2 v3 3 3 The 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. 4 4 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. 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. 6 7 Furthermore, it is possible to filter the key records by a type field (which should be int) for certain options. 6 8 7 9 Usage: … … 11 13 - ''keyfield'' = Name of the key field 12 14 - ''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 o f 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 for15 - 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 17 19 - filter_opts=''"options"'' = a list or tuple of allowed values for the filterby-field 18 20 … … 28 30 29 31 db[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) 34 36 )) 35 37 }}}