Changes between Version 57 and Version 58 of S3/S3REST/s3_rest_controller
- Timestamp:
- 02/15/11 12:41:06 (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
S3/S3REST/s3_rest_controller
v57 v58 312 312 === Filtering Lists === 313 313 314 You can filter lists by setting {{{response.s3.filter}}} to a filter query: 315 314 You can filter lists in the controller by setting {{{response.s3.filter}}} to a filter query: 316 315 {{{ 317 316 # This filters for females: … … 321 320 }}} 322 321 322 Note that this only takes effect in the main controller (not in prep or postp). 323 323 324 Note that {{{response.s3.filter}}} affects both, the primary resource and components! 324 325 325 326 In {{{prep}}}, you can also add filter queries using the {{{add_filter}}} method: 326 327 327 {{{ 328 328 def prep(r): 329 329 resource = r.resource 330 query = (db.pr_address.type ==1) # Home addresses only330 query = (db.pr_address.type == 1) # Home addresses only 331 331 resource.add_filter(query) 332 332 return True … … 337 337 338 338 However, {{{add_filter}}} again affects both, primary and component records - so this example would: 339 340 339 - only retrieve {{{person}}} records which have a type 1 {{{address}}} record 341 340 - only retrieve the {{{address}}} records with type 1. … … 344 343 345 344 To have the primary resource unfiltered, and filter only records in a particular component, you can use {{{add_component_filter}}}: 346 347 345 {{{ 348 346 def prep(r): 349 347 resource = r.resource 350 query = (db.pr_address.type ==1) # Home addresses only348 query = (db.pr_address.type == 1) # Home addresses only 351 349 resource.add_component_filter("address", query) 352 350 return True … … 357 355 358 356 In this case, all {{{person}}} records would be selected - while only {{{address}}} records of type 1 would be retrieved. 359 360 361 357 === Pre-populating Create-Forms === 362 358