QuerySet

Extended queryset with column-oriented access.

Usage

Source

QuerySet()
Note

See source for available aggregate spatial functions if django.contrib.gis is configured.

Methods

Name Description
__contains__() Return whether value is present using exists.
__eq__() Return [QuerySet][model_values.QuerySet] filtered by comparison to given value.
__getitem__() Allow column access by field names, expressions, or F objects.
__iter__() Iteration extended to support [group_by][model_values.QuerySet.group_by].
__setitem__() Update a single column.
alias() Alias extended to also handle mapping values, as a [Case][model_values.Case] expression.
annotate() Annotate extended to also handle mapping values, as a [Case][model_values.Case] expression.
change() Update and return number of rows that actually changed.
changed() Return first mapping of fields and values which differ in the db.
exists() Return whether there are at least the specified number of rows.
group_by() Return a grouped [QuerySet][model_values.QuerySet].
reduce() Return aggregated values, or an annotated [QuerySet][model_values.QuerySet].
select() Return annotated values_list.
sort() Return [QuerySet][model_values.QuerySet] ordered by selected values.
update() Update extended to also handle mapping values, as a [Case][model_values.Case] expression.
value_counts() Return annotated value counts.

__contains__()

Return whether value is present using exists.

Usage

Source

__contains__(value)

__eq__()

Return [QuerySet][model_values.QuerySet] filtered by comparison to given value.

Usage

Source

__eq__(value, lookup="")

__getitem__()

Allow column access by field names, expressions, or F objects.

Usage

Source

__getitem__(key)

qs[field] returns flat values_list

qs[field, ...] returns tupled values_list


__iter__()

Iteration extended to support [group_by][model_values.QuerySet.group_by].

Usage

Source

__iter__()

__setitem__()

Update a single column.

Usage

Source

__setitem__(key, value)

alias()

Alias extended to also handle mapping values, as a [Case][model_values.Case] expression.

Usage

Source

alias(*args, **kwargs)
Parameters
**kwargs
field={Q_obj: value, ...}, ...

annotate()

Annotate extended to also handle mapping values, as a [Case][model_values.Case] expression.

Usage

Source

annotate(*args, **kwargs)
Parameters
**kwargs
field={Q_obj: value, ...}, ...

As a provisional feature, an optional default key may be specified.


change()

Update and return number of rows that actually changed.

Usage

Source

change(defaults={}, **kwargs)

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
defaults: Mapping = {}
optional mapping which will be updated conditionally, as with update_or_create.

changed()

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

Usage

Source

changed(**kwargs)

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


exists()

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

Usage

Source

exists(count=1)

group_by()

Return a grouped [QuerySet][model_values.QuerySet].

Usage

Source

group_by(*fields, **annotations)

The queryset is iterable in the same manner as itertools.groupby. Additionally the [reduce][model_values.QuerySet.reduce] functions will return annotated querysets.


reduce()

Return aggregated values, or an annotated [QuerySet][model_values.QuerySet].

Usage

Source

reduce(*funcs, **extra)
Parameters
*funcs
aggregation function classes

select()

Return annotated values_list.

Usage

Source

select(*fields, **annotations)

sort()

Return [QuerySet][model_values.QuerySet] ordered by selected values.

Usage

Source

sort(reverse=False)

update()

Update extended to also handle mapping values, as a [Case][model_values.Case] expression.

Usage

Source

update(**kwargs)
Parameters
**kwargs
field={Q_obj: value, ...}, ...

value_counts()

Return annotated value counts.

Usage

Source

value_counts(alias="count")