Reference
Note
Spatial lookups require gis to be enabled.
Mixin for field lookups.
Source code in model_values/__init__.py
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
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
range(*values)
¶
relate(*values)
¶
within(geom, distance=None)
¶
Return whether field is within geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distance
|
|
None
|
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.
Bases: ,
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
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 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 | |
distance
¶
Bases:
Return Distance with support for lookups: <, <=, >, >=, within.
Source code in model_values/__init__.py
__eq__(value, lookup='')
¶
Return Q object with lookup.
__getattr__(name)
¶
__getitem__(slc)
¶
Return field Substr or Right.
Source code in model_values/__init__.py
__ne__(value)
¶
count(**extra)
¶
find(sub, **extra)
¶
ljust(width, fill=' ', **extra)
¶
log(base=math.e, **extra)
¶
replace(old, new='', **extra)
¶
Note
See source for available aggregate spatial functions if gis is configured.
Bases: ,
Source code in model_values/__init__.py
336 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 511 512 513 514 515 | |
__contains__(value)
¶
__eq__(value, lookup='')
¶
Return [QuerySet][model_values.QuerySet] filtered by comparison to given value.
__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][model_values.QuerySet]
Source code in model_values/__init__.py
__iter__()
¶
Iteration extended to support [group_by][model_values.QuerySet.group_by].
Source code in model_values/__init__.py
__setitem__(key, value)
¶
alias(*args, **kwargs)
¶
Alias extended to also handle mapping values, as a [Case][model_values.Case] expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
|
{}
|
Source code in model_values/__init__.py
annotate(*args, **kwargs)
¶
Annotate extended to also handle mapping values, as a [Case][model_values.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
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
|
|
optional mapping which will be updated conditionally, as with |
{}
|
Source code in model_values/__init__.py
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
exists(count=1)
¶
Return whether there are at least the specified number of rows.
group_by(*fields, **annotations)
¶
Return a grouped [QuerySet][model_values.QuerySet].
The queryset is iterable in the same manner as itertools.groupby.
Additionally the [reduce][model_values.QuerySet.reduce] functions will return annotated querysets.
Source code in model_values/__init__.py
reduce(*funcs, **extra)
¶
Return aggregated values, or an annotated [QuerySet][model_values.QuerySet].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*funcs
|
aggregation function classes |
()
|
Source code in model_values/__init__.py
select(*fields, **annotations)
¶
sort(reverse=False)
¶
Return [QuerySet][model_values.QuerySet] ordered by selected values.
update(**kwargs)
¶
Update extended to also handle mapping values, as a [Case][model_values.Case] expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
|
{}
|
Source code in model_values/__init__.py
Bases:
Source code in model_values/__init__.py
__contains__(pk)
¶
__delitem__(pk)
¶
__getitem__(pk)
¶
Return [QuerySet][model_values.QuerySet] which matches primary key.
To encourage direct db access, instead of always using get and save.
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
|
|
|
required |
key
|
|
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
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
|
|
|
required |
key
|
|
unique key column |
'pk'
|
Source code in model_values/__init__.py
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
|
|
optional mapping which will be updated, as with |
{}
|
Source code in model_values/__init__.py
Bases:
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
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
|
|
optional callable to transform enum names to display labels, thereby using enum values as db values and also supporting integers. |
None
|