Reference
Note
Spatial lookups require gis to be enabled.
model_values.Lookup
Mixin for field lookups.
Source code in model_values/__init__.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 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 |
|
is_valid
property
Whether field isvalid
.
contains(value, properly=False, bb=False)
Return whether field contains
the value. Options apply only to geom fields.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
properly |
|
False
|
|
bb |
bounding box, |
False
|
Source code in model_values/__init__.py
75 76 77 78 79 80 81 82 83 84 |
|
overlaps(geom, position='', bb=False)
Return whether field overlaps
with geometry .
Parameters:
Name | Type | Description | Default |
---|---|---|---|
position |
|
''
|
|
bb |
bounding box, |
False
|
Source code in model_values/__init__.py
86 87 88 89 90 91 92 93 94 |
|
range(*values)
range
Source code in model_values/__init__.py
62 63 64 |
|
relate(*values)
relate
Source code in model_values/__init__.py
66 67 68 |
|
within(geom, distance=None)
Return whether field is within
geometry.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
distance |
|
None
|
Source code in model_values/__init__.py
96 97 98 99 100 101 102 103 104 |
|
Note
Since attributes are used for constructing F objects, there may be collisions between field names and methods. For example, name
is a reserved attribute, but the usual constructor can still be used: F('name')
.
Note
See source for available spatial functions if gis is configured.
model_values.F
Bases: F
, Lookup
Create F
, Q
, and Func
objects with expressions.
F
creation supported as attributes:
F.user
== F('user')
,
F.user.created
== F('user__created')
.
Q
lookups supported as methods or operators:
F.text.iexact(...)
== Q(text__iexact=...)
,
F.user.created >= ...
== Q(user__created__gte=...)
.
Func
objects also supported as methods:
F.user.created.min()
== Min('user__created')
.
Some Func
objects can also be transformed into lookups,
if registered:
F.text.length()
== Length(F('text'))
,
F.text.length > 0
== Q(text__length__gt=0)
.
Source code in model_values/__init__.py
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 262 263 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 |
|
distance
Bases: Distance
Return Distance
with support for lookups: <, <=, >, >=, within.
Source code in model_values/__init__.py
252 253 254 255 256 257 258 259 260 |
|
__eq__(value, lookup='')
Return Q
object with lookup.
Source code in model_values/__init__.py
266 267 268 269 270 |
|
__getattr__(name)
Return new F object with chained attribute.
Source code in model_values/__init__.py
262 263 264 |
|
__getitem__(slc)
Return field Substr
or Right
.
Source code in model_values/__init__.py
287 288 289 290 291 292 293 294 295 |
|
__ne__(value)
Allow __ne=None lookup without custom queryset.
Source code in model_values/__init__.py
272 273 274 275 276 |
|
count(**extra)
Return Count
with optional field.
Source code in model_values/__init__.py
303 304 305 306 |
|
find(sub, **extra)
Return StrIndex
with str.find
semantics.
Source code in model_values/__init__.py
308 309 310 |
|
ljust(width, fill=' ', **extra)
Return LPad
with wrapped values.
Source code in model_values/__init__.py
316 317 318 |
|
log(base=math.e, **extra)
Return Log
, by default Ln
.
Source code in model_values/__init__.py
324 325 326 |
|
replace(old, new='', **extra)
Return Replace
with wrapped values.
Source code in model_values/__init__.py
312 313 314 |
|
rjust(width, fill=' ', **extra)
Return RPad
with wrapped values.
Source code in model_values/__init__.py
320 321 322 |
|
Note
See source for available aggregate spatial functions if gis is configured.
model_values.QuerySet
Bases: QuerySet
, Lookup
Source code in model_values/__init__.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 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 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 |
|
__contains__(value)
Return whether value is present using exists
.
Source code in model_values/__init__.py
392 393 394 395 396 |
|
__eq__(value, lookup='')
Return QuerySet filtered by comparison to given value.
Source code in model_values/__init__.py
387 388 389 390 |
|
__getitem__(key)
Allow column access by field names, expressions, or F
objects.
qs[field]
returns flat values_list
qs[field, ...]
returns tupled values_list
qs[Q_obj]
provisionally returns filtered QuerySet
Source code in model_values/__init__.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
|
__iter__()
Iteration extended to support groupby.
Source code in model_values/__init__.py
398 399 400 401 402 403 404 405 406 407 408 409 |
|
__setitem__(key, value)
Update a single column.
Source code in model_values/__init__.py
383 384 385 |
|
alias(*args, **kwargs)
Alias extended to also handle mapping values, as a Case expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs |
|
{}
|
Source code in model_values/__init__.py
438 439 440 441 442 443 444 445 446 447 |
|
annotate(*args, **kwargs)
Annotate extended to also handle mapping values, as a Case expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs |
|
{}
|
As a provisional feature, an optional default
key may be specified.
Source code in model_values/__init__.py
425 426 427 428 429 430 431 432 433 434 435 436 |
|
change(defaults={}, **kwargs)
Update and return number of rows that actually changed.
For triggering on-change logic without fetching first.
if qs.change(status=...):
status actually changed
qs.change({'last_modified': now}, status=...)
last_modified only updated if status updated
Parameters:
Name | Type | Description | Default |
---|---|---|---|
defaults |
Mapping
|
optional mapping which will be updated conditionally, as with |
{}
|
Source code in model_values/__init__.py
484 485 486 487 488 489 490 491 492 493 494 495 496 |
|
changed(**kwargs)
Return first mapping of fields and values which differ in the db.
Also efficient enough to be used in boolean contexts, instead of exists
.
Source code in model_values/__init__.py
498 499 500 501 502 503 504 |
|
exists(count=1)
Return whether there are at least the specified number of rows.
Source code in model_values/__init__.py
506 507 508 509 510 |
|
groupby(*fields, **annotations)
Return a grouped QuerySet.
The queryset is iterable in the same manner as itertools.groupby
.
Additionally the reduce functions will return annotated querysets.
Source code in model_values/__init__.py
415 416 417 418 419 420 421 422 423 |
|
items(*fields, **annotations)
Return annotated values_list
.
Source code in model_values/__init__.py
411 412 413 |
|
reduce(*funcs, **extra)
Return aggregated values, or an annotated QuerySet.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*funcs |
aggregation function classes |
()
|
Source code in model_values/__init__.py
458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
|
sort_values(reverse=False)
Return QuerySet ordered by selected values.
Source code in model_values/__init__.py
453 454 455 456 |
|
update(**kwargs)
Update extended to also handle mapping values, as a Case expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs |
|
{}
|
Source code in model_values/__init__.py
473 474 475 476 477 478 479 480 481 482 |
|
value_counts(alias='count')
Return annotated value counts.
Source code in model_values/__init__.py
449 450 451 |
|
model_values.Manager
Bases: Manager
Source code in model_values/__init__.py
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 |
|
__contains__(pk)
Return whether primary key is present using exists
.
Source code in model_values/__init__.py
549 550 551 |
|
__delitem__(pk)
Delete row with primary key.
Source code in model_values/__init__.py
545 546 547 |
|
__getitem__(pk)
Return QuerySet which matches primary key.
To encourage direct db access, instead of always using get and save.
Source code in model_values/__init__.py
538 539 540 541 542 543 |
|
bulk_change(field, data, key='pk', conditional=False, **kwargs)
Update changed rows with a minimal number of queries, by inverting the data to use pk__in
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
field |
value column |
required | |
data |
Mapping
|
|
required |
key |
str
|
unique key column |
'pk'
|
conditional |
execute select query and single conditional update; may be more efficient if the percentage of changed rows is relatively small |
False
|
|
**kwargs |
additional fields to be updated |
{}
|
Source code in model_values/__init__.py
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 |
|
bulk_changed(field, data, key='pk')
Return mapping of values which differ in the db.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
field |
value column |
required | |
data |
Mapping
|
|
required |
key |
str
|
unique key column |
'pk'
|
Source code in model_values/__init__.py
572 573 574 575 576 577 578 579 580 581 |
|
upsert(defaults={}, **kwargs)
Update or insert returning number of rows or created object.
Faster and safer than update_or_create
.
Supports combined expression updates by assuming the identity element on insert: F(...) + 1
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
defaults |
Mapping
|
optional mapping which will be updated, as with |
{}
|
Source code in model_values/__init__.py
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 |
|
model_values.Case
Bases: Case
Case
expression from mapping of when conditionals.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conds |
|
required | |
default |
optional default value or |
required |
Source code in model_values/__init__.py
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 |
|
model_values.classproperty
Bases: property
A property bound to a class.
Source code in model_values/__init__.py
609 610 611 612 613 |
|
model_values.EnumField(enum, display=None, **options)
Return a CharField
or IntegerField
with choices from given enum.
By default, enum names and values are used as db values and display labels respectively,
returning a CharField
with computed max_length
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
display |
Callable | None
|
optional callable to transform enum names to display labels, thereby using enum values as db values and also supporting integers. |
None
|
Source code in model_values/__init__.py
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 |
|