filter_action
FilterAction
Bases: QueryAction
Represents a single WHERE predicate on a queryset.
Created for each key=value (or key__op=value) passed to
filter(...) / exclude(...) and to filtering shortcuts like
get(...) / first(...).
Source code in ormar/queryset/actions/filter_action.py
| Python | |
|---|---|
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
binds_slot()
Return whether the value is bound as a parameter: SQLAlchemy renders
None (IS NULL), booleans and isnull checks into the SQL text.
Only values that are bound can get a named slot in a statement
template. The others stay in the SQL text and become part of the
template's cache key instead (see templates.value_cache_key)::
| Text Only | |
|---|---|
1 2 | |
Returns:
| Type | Description |
|---|---|
bool
|
True when the value is sent as a bound parameter |
Source code in ormar/queryset/actions/filter_action.py
| Python | |
|---|---|
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
bound_value()
Return the value bound to the query: an ormar Model is replaced by its
value it is referenced by (its primary key or the foreign key's
to_field), so filter(author=author) binds author.pk.
filter_value itself is left untouched, so the action can be read
again on every call to collect the value for a cached template.
Returns:
| Type | Description |
|---|---|
Any
|
value to bind |
Source code in ormar/queryset/actions/filter_action.py
| Python | |
|---|---|
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_text_clause(binder=None)
Escapes characters if it's required. Substitutes values of the models if value is a ormar Model with its pk value. Compiles the clause.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
binder
|
Optional[SlotBinder]
|
names the bound value for statement templates
( |
None
|
Returns:
| Type | Description |
|---|---|
sqlalchemy.sql.elements.TextClause
|
complied and escaped clause |
Source code in ormar/queryset/actions/filter_action.py
| Python | |
|---|---|
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
has_escaped_characters()
Check if value is a string that contains characters to escape
Source code in ormar/queryset/actions/filter_action.py
| Python | |
|---|---|
126 127 128 129 130 | |
path_actions()
Returns:
| Type | Description |
|---|---|
list[QueryAction]
|
the action and the fields its expression reads, each resolving one relation path to a joined table |
Source code in ormar/queryset/actions/filter_action.py
| Python | |
|---|---|
103 104 105 106 107 108 109 | |
update_select_related(select_related)
Add the joins of the filtered field and of the fields its expression
reads (see QueryAction.update_select_related).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
select_related
|
list[str]
|
list of relation join strings |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list of relation joins with implied joins from filter added |
Source code in ormar/queryset/actions/filter_action.py
| Python | |
|---|---|
111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
KeyInFilterAction
Bases: FilterAction
pk__in filter on a composite primary key, compiled to one row-value
IN over the key columns::
| Text Only | |
|---|---|
1 2 | |
The values are bound as one expanding parameter, so every list length
shares one statement. With columns the action compares other columns
of the table, e.g. the columns of a foreign key stored in several columns
(anchor names the field the columns belong to)::
| Text Only | |
|---|---|
1 2 | |
Source code in ormar/queryset/actions/filter_action.py
| Python | |
|---|---|
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | |
__init__(*, prefix, values, model_cls, anchor=None, columns=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
str
|
relation path to the filtered model, |
required |
values
|
list[tuple[Any, ...]]
|
key values as tuples of parts in key order |
required |
model_cls
|
type[Model]
|
queried model |
required |
Source code in ormar/queryset/actions/filter_action.py
| Python | |
|---|---|
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | |
get_text_clause(binder=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
binder
|
Optional[SlotBinder]
|
names the bound values for statement templates, if given |
None
|
Returns:
| Type | Description |
|---|---|
TextClause
|
row-value |
Source code in ormar/queryset/actions/filter_action.py
| Python | |
|---|---|
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | |
key_columns()
Returns:
| Type | Description |
|---|---|
list[sqlalchemy.Column]
|
columns of the key, aliased to the table prefix of the filter |
Source code in ormar/queryset/actions/filter_action.py
| Python | |
|---|---|
323 324 325 326 327 328 329 330 331 | |
key_operator()
staticmethod
Returns:
| Type | Description |
|---|---|
str
|
lookup operator of the action |
Source code in ormar/queryset/actions/filter_action.py
| Python | |
|---|---|
315 316 317 318 319 320 321 | |
KeyNullFilterAction
Bases: KeyInFilterAction
isnull filter on a foreign key stored in several columns: a relation
with any column null references no row, so it counts as missing::
| Text Only | |
|---|---|
1 2 | |
Source code in ormar/queryset/actions/filter_action.py
| Python | |
|---|---|
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
get_text_clause(binder=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
binder
|
Optional[SlotBinder]
|
slot binder of a statement template (unused, nothing is bound) |
None
|
Returns:
| Type | Description |
|---|---|
TextClause
|
the null checks of the key columns |
Source code in ormar/queryset/actions/filter_action.py
| Python | |
|---|---|
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
key_operator()
staticmethod
Returns:
| Type | Description |
|---|---|
str
|
lookup operator of the action |
Source code in ormar/queryset/actions/filter_action.py
| Python | |
|---|---|
360 361 362 363 364 365 366 | |
split_filter_key(key)
Split a filter key into its operator and the path of the filtered field. A trailing operator name is always the operator, so a field named like an operator is filtered with an explicit one::
| Text Only | |
|---|---|
1 2 | |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
filter key |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, list[str]]
|
operator ( |
Raises:
| Type | Description |
|---|---|
QueryDefinitionError
|
if the key is only an operator |
Source code in ormar/queryset/actions/filter_action.py
| Python | |
|---|---|
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |