class Expression
[source]
-
contains_aggregate
-
Tells Django that this expression contains an aggregate and that a
GROUP BY
clause needs to be added to the query.
-
resolve_expression(query=None, allow_joins=True, reuse=None, summarize=False, for_save=False)
-
Provides the chance to do any pre-processing or validation of the expression before it’s added to the query.
resolve_expression()
must also be called on any nested expressions. Acopy()
ofself
should be returned with any necessary transformations.query
is the backend query implementation.allow_joins
is a boolean that allows or denies the use of joins in the query.reuse
is a set of reusable joins for multi-join scenarios.summarize
is a boolean that, whenTrue
, signals that the query being computed is a terminal aggregate query.
-
get_source_expressions()
-
Returns an ordered list of inner expressions. For example:
12>>>
Sum
(F(
'foo'
)).get_source_expressions()
[F(
'foo'
)]
-
set_source_expressions(expressions)
-
Takes a list of expressions and stores them such that
get_source_expressions()
can return them.
-
relabeled_clone(change_map)
-
Returns a clone (copy) of
self
, with any column aliases relabeled. Column aliases are renamed when subqueries are created.relabeled_clone()
should also be called on any nested expressions and assigned to the clone.change_map
is a dictionary mapping old aliases to new aliases.Example:
1234def
relabeled_clone(
self
, change_map):
clone
=
copy.copy(
self
)
clone.expression
=
self
.expression.relabeled_clone(change_map)
return
clone
-
convert_value(self, value, expression, connection, context)
-
A hook allowing the expression to coerce
value
into a more appropriate type.
-
get_group_by_cols()
-
Responsible for returning the list of columns references by this expression.
get_group_by_cols()
should be called on any nested expressions.F()
objects, in particular, hold a reference to a column.
-
asc()
-
Returns the expression ready to be sorted in ascending order.
-
desc()
-
Returns the expression ready to be sorted in descending order.
-
reverse_ordering()
-
Returns
self
with any modifications required to reverse the sort order within anorder_by
call. As an example, an expression implementingNULLS LAST
would change its value to beNULLS FIRST
. Modifications are only required for expressions that implement sort order likeOrderBy
. This method is called whenreverse()
is called on a queryset.
Please login to continue.