|
@@ -147,7 +147,6 @@ class Combinable:
|
|
|
)
|
|
|
|
|
|
|
|
|
-@deconstructible
|
|
|
class BaseExpression:
|
|
|
"""Base class for all query expressions."""
|
|
|
|
|
@@ -389,6 +388,11 @@ class BaseExpression:
|
|
|
return self.output_field.select_format(compiler, sql, params)
|
|
|
return sql, params
|
|
|
|
|
|
+
|
|
|
+@deconstructible
|
|
|
+class Expression(BaseExpression, Combinable):
|
|
|
+ """An expression that can be combined with other expressions."""
|
|
|
+
|
|
|
@cached_property
|
|
|
def identity(self):
|
|
|
constructor_signature = inspect.signature(self.__init__)
|
|
@@ -409,7 +413,7 @@ class BaseExpression:
|
|
|
return tuple(identity)
|
|
|
|
|
|
def __eq__(self, other):
|
|
|
- if not isinstance(other, BaseExpression):
|
|
|
+ if not isinstance(other, Expression):
|
|
|
return NotImplemented
|
|
|
return other.identity == self.identity
|
|
|
|
|
@@ -417,11 +421,6 @@ class BaseExpression:
|
|
|
return hash(self.identity)
|
|
|
|
|
|
|
|
|
-class Expression(BaseExpression, Combinable):
|
|
|
- """An expression that can be combined with other expressions."""
|
|
|
- pass
|
|
|
-
|
|
|
-
|
|
|
_connector_combinators = {
|
|
|
connector: [
|
|
|
(fields.IntegerField, fields.IntegerField, fields.IntegerField),
|
|
@@ -1103,7 +1102,7 @@ class Case(Expression):
|
|
|
return super().get_group_by_cols(alias)
|
|
|
|
|
|
|
|
|
-class Subquery(Expression):
|
|
|
+class Subquery(BaseExpression, Combinable):
|
|
|
"""
|
|
|
An explicit subquery. It may contain OuterRef() references to the outer
|
|
|
query which will be resolved when it is applied to that query.
|
|
@@ -1117,16 +1116,6 @@ class Subquery(Expression):
|
|
|
self.extra = extra
|
|
|
super().__init__(output_field)
|
|
|
|
|
|
- def __getstate__(self):
|
|
|
- state = super().__getstate__()
|
|
|
- args, kwargs = state['_constructor_args']
|
|
|
- if args:
|
|
|
- args = (self.query, *args[1:])
|
|
|
- else:
|
|
|
- kwargs['queryset'] = self.query
|
|
|
- state['_constructor_args'] = args, kwargs
|
|
|
- return state
|
|
|
-
|
|
|
def get_source_expressions(self):
|
|
|
return [self.query]
|
|
|
|
|
@@ -1203,6 +1192,7 @@ class Exists(Subquery):
|
|
|
return sql, params
|
|
|
|
|
|
|
|
|
+@deconstructible
|
|
|
class OrderBy(BaseExpression):
|
|
|
template = '%(expression)s %(ordering)s'
|
|
|
conditional = False
|