mirror of
https://github.com/django/django.git
synced 2025-08-23 20:14:17 +00:00
Fixed #24793 -- Unified temporal difference support.
This commit is contained in:
parent
31098e3288
commit
766afc22a1
14 changed files with 135 additions and 2 deletions
|
@ -398,6 +398,10 @@ class CombinedExpression(Expression):
|
|||
((lhs_output and lhs_output.get_internal_type() == 'DurationField')
|
||||
or (rhs_output and rhs_output.get_internal_type() == 'DurationField'))):
|
||||
return DurationExpression(self.lhs, self.connector, self.rhs).as_sql(compiler, connection)
|
||||
if (lhs_output and rhs_output and self.connector == self.SUB and
|
||||
lhs_output.get_internal_type() in {'DateField', 'DateTimeField', 'TimeField'} and
|
||||
lhs_output.get_internal_type() == lhs_output.get_internal_type()):
|
||||
return TemporalSubtraction(self.lhs, self.rhs).as_sql(compiler, connection)
|
||||
expressions = []
|
||||
expression_params = []
|
||||
sql, params = compiler.compile(self.lhs)
|
||||
|
@ -448,6 +452,17 @@ class DurationExpression(CombinedExpression):
|
|||
return expression_wrapper % sql, expression_params
|
||||
|
||||
|
||||
class TemporalSubtraction(CombinedExpression):
|
||||
def __init__(self, lhs, rhs):
|
||||
super(TemporalSubtraction, self).__init__(lhs, self.SUB, rhs, output_field=fields.DurationField())
|
||||
|
||||
def as_sql(self, compiler, connection):
|
||||
connection.ops.check_expression_support(self)
|
||||
lhs = compiler.compile(self.lhs, connection)
|
||||
rhs = compiler.compile(self.rhs, connection)
|
||||
return connection.ops.subtract_temporals(self.lhs.output_field.get_internal_type(), lhs, rhs)
|
||||
|
||||
|
||||
class F(Combinable):
|
||||
"""
|
||||
An object capable of resolving references to existing query objects.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue