mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Refs #25287 -- Added support for multiplying and dividing DurationField by scalar values on SQLite.
This commit is contained in:
committed by
Mariusz Felisiak
parent
9e1ccd7283
commit
54e94640ac
@@ -1530,6 +1530,36 @@ class FTimeDeltaTests(TestCase):
|
||||
))
|
||||
self.assertIsNone(queryset.first().shifted)
|
||||
|
||||
def test_durationfield_multiply_divide(self):
|
||||
Experiment.objects.update(scalar=2)
|
||||
tests = [
|
||||
(Decimal('2'), 2),
|
||||
(F('scalar'), 2),
|
||||
(2, 2),
|
||||
(3.2, 3.2),
|
||||
]
|
||||
for expr, scalar in tests:
|
||||
with self.subTest(expr=expr):
|
||||
qs = Experiment.objects.annotate(
|
||||
multiplied=ExpressionWrapper(
|
||||
expr * F('estimated_time'),
|
||||
output_field=DurationField(),
|
||||
),
|
||||
divided=ExpressionWrapper(
|
||||
F('estimated_time') / expr,
|
||||
output_field=DurationField(),
|
||||
),
|
||||
)
|
||||
for experiment in qs:
|
||||
self.assertEqual(
|
||||
experiment.multiplied,
|
||||
experiment.estimated_time * scalar,
|
||||
)
|
||||
self.assertEqual(
|
||||
experiment.divided,
|
||||
experiment.estimated_time / scalar,
|
||||
)
|
||||
|
||||
def test_duration_expressions(self):
|
||||
for delta in self.deltas:
|
||||
qs = Experiment.objects.annotate(duration=F('estimated_time') + delta)
|
||||
|
||||
Reference in New Issue
Block a user