Lookup¶
-
class
model_values.
Lookup
[source]¶ Mixin for field lookups.
-
__ge__
(value)¶ gte
-
__gt__
(value)¶ gt
-
__le__
(value)¶ lte
-
__lt__
(value)¶ lt
-
__ne__
(value)¶ ne
-
contains
(value)¶
-
endswith
(value)¶
-
icontains
(value)¶
-
iendswith
(value)¶
-
iexact
(value)¶
-
iregex
(value)¶
-
istartswith
(value)¶
-
regex
(value)¶
-
search
(value)¶
-
startswith
(value)¶
-
F¶
-
class
model_values.
FExpr
(name)[source]¶ Bases:
django.db.models.expressions.F
,model_values.Lookup
Singleton for creating
F
,Q
,Func
, andOrderBy
objects with expressions.F.user.created
==F('user__created')
F.user.created >= ...
==Q(user__created__gte=...)
F.user.created.min()
==Min('user__created')
-F.user.created
==F('user__created').desc()
F.text.iexact(...)
==Q(text__iexact=...)
-
__or__
(*args, **extra)¶ Coalesce
-
concat
(*args, **extra)¶ Concat
-
count
(*args, **extra)¶ Count
-
length
(*args, **extra)¶ Length
-
lower
(*args, **extra)¶ Lower
-
max
(*args, **extra)¶ Max
-
mean
(*args, **extra)¶ Avg
-
min
(*args, **extra)¶ Min
-
std
(*args, **extra)¶ StdDev
-
sum
(*args, **extra)¶ Sum
-
upper
(*args, **extra)¶ Upper
-
var
(*args, **extra)¶ Variance
-
QuerySet¶
-
class
model_values.
QuerySet
(model=None, query=None, using=None, hints=None)[source]¶ Bases:
django.db.models.query.QuerySet
,model_values.Lookup
-
__div__
(value)¶ F / value.
-
__getitem__
(key)[source]¶ Allow column access by field names (or
F
objects) and filtering byQ
objects.qs[field]
returns flatvalues_list
qs[field, ...]
returns tupledvalues_list
qs[Q_obj]
returns filtered QuerySet
-
annotate
(*args, **kwargs)[source]¶ Annotate extended to also handle mapping values, as a case expression.
Parameters: kwargs – field={Q_obj: value, ...}, ...
-
groupby
(*fields, **annotations)[source]¶ Return a grouped QuerySet.
The queryset is iterable in the same manner as
itertools.groupby
. Additionally thereduce
functions will return annotated querysets.
-
max
()¶ Max
-
mean
()¶ Avg
-
min
()¶ Min
-
modify
(defaults=(), **kwargs)[source]¶ Update and return number of rows that actually changed.
For triggering on-change logic without fetching first.
if qs.modify(status=...):
status actually changedqs.modify({'last_modified': now}, status=...)
last_modified only updated if status updatedParameters: defaults – optional mapping which will be updated conditionally, as with update_or_create
.
-
reduce
(*funcs)[source]¶ Return aggregated values, or an annotated QuerySet if
groupby
is in use.Parameters: funcs – aggregation function classes
-
std
()¶ StdDev
-
sum
()¶ Sum
-
update
(**kwargs)[source]¶ Update extended to also handle mapping values, as a case expression.
Parameters: kwargs – field={Q_obj: value, ...}, ...
-
upsert
(defaults={}, **kwargs)[source]¶ 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: defaults – optional mapping which will be updated, as with update_or_create
.
-
var
()¶ Variance
-
Manager¶
-
class
model_values.
Manager
[source]¶ Bases:
django.db.models.manager.Manager
-
__getitem__
(pk)[source]¶ Return QuerySet which matches primary key.
To encourage direct db access, instead of always using get and save.
-
bulk_changed
(field, data)[source]¶ Return mapping of values which differ in the db.
Parameters: data – {pk: value, ...}
-
bulk_update
(field, data, changed=False, conditional=False, **kwargs)[source]¶ Update with a minimal number of queries, by inverting the data to use
pk__in
.Parameters: - data –
{pk: value, ...}
- changed – execute select query first to update only rows which differ; more efficient if the expected percentage of changed rows is relatively small
- conditional – execute a single query with a conditional expression; may be more efficient if the number of rows is large (but bounded)
- kwargs – additional fields to be updated
- data –
-