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)
in_(*values)[source]

in

iregex(value)
istartswith(value)
range(*values)[source]
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, and OrderBy 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=...)

__call__(name)

Return new F object with chained attribute.

__eq__(value, lookup='')[source]

Return Q object with lookup.

__getattr__(name)[source]

Return new F object with chained attribute.

__getitem__(slc)[source]

Return field Substr.

__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

__add__(value)[source]

F + value.

__contains__(value)[source]

Return whether value is present using exists.

__div__(value)

F / value.

__eq__(value, lookup='')[source]

Return QuerySet filtered by comparison to given value.

__getitem__(key)[source]

Allow column access by field names (or F objects) and filtering by Q objects.

qs[field] returns flat values_list

qs[field, ...] returns tupled values_list

qs[Q_obj] returns filtered QuerySet

__mod__(value)[source]

F % value.

__mul__(value)[source]

F * value.

__pow__(value)[source]

F ** value.

__setitem__(key, value)[source]

Update a single column.

__sub__(value)[source]

F - value.

__truediv__(value)[source]

F / value.

annotate(*args, **kwargs)[source]

Annotate extended to also handle mapping values, as a case expression.

Parameters:kwargsfield={Q_obj: value, ...}, ...
exists(count=1)[source]

Return whether there are at least the specified number of rows.

groupby(*fields, **annotations)[source]

Return a grouped QuerySet.

The queryset is iterable in the same manner as itertools.groupby. Additionally the reduce 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 changed

qs.modify({'last_modified': now}, status=...) last_modified only updated if status updated

Parameters: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:kwargsfield={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.
value_counts(alias='count')[source]

Return annotated value counts.

var()

Variance

Manager

class model_values.Manager[source]

Bases: django.db.models.manager.Manager

__contains__(pk)[source]

Return whether pk is present using exists.

__delitem__(pk)[source]

Delete row with primary key.

__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
changed(pk, **kwargs)[source]

Return mapping of fields and values which differ in the db.

Also efficient enough to be used in boolean contexts, instead of exists.

classproperty

class model_values.classproperty[source]

Bases: property

A property bound to a class.