| | 175 | Or more complex: |
| | 176 | |
| | 177 | {{{ |
| | 178 | for x in y: |
| | 179 | if x.a == some_value or other_variable == other_value: |
| | 180 | record = db(db.mytable.id == x.key).select() |
| | 181 | ...<branch 1> |
| | 182 | else: |
| | 183 | record = db(db.othertable.id == x.other_key).select() |
| | 184 | ...<branch 2> |
| | 185 | }}} |
| | 186 | |
| | 187 | could be: |
| | 188 | |
| | 189 | {{{ |
| | 190 | if other_variable == other_value: |
| | 191 | ids1 = [x.key for x in y] |
| | 192 | ids2 = [] |
| | 193 | else: |
| | 194 | ids1 = filter(lambda x: (x.a == some_value) and x.key or None, y) |
| | 195 | ids2 = filter(lambda x: (x.a != some_value) and x.other_key or None, y) |
| | 196 | if ids1: |
| | 197 | records = db(db.mytable.id.belongs(ids1)).select() |
| | 198 | for record in records: |
| | 199 | ...<branch 1> |
| | 200 | if ids2: |
| | 201 | records = db(db.othertable.id.belongs(ids2)).select() |
| | 202 | for record in records: |
| | 203 | ...<branch 2> |
| | 204 | }}} |
| | 205 | |