diff options
Diffstat (limited to 'tests/custom_lookups')
| -rw-r--r-- | tests/custom_lookups/tests.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/custom_lookups/tests.py b/tests/custom_lookups/tests.py index 9661aebc49..418525c3ed 100644 --- a/tests/custom_lookups/tests.py +++ b/tests/custom_lookups/tests.py @@ -63,6 +63,14 @@ class Mult3BilateralTransform(models.Transform): return '3 * (%s)' % lhs, lhs_params +class LastDigitTransform(models.Transform): + lookup_name = 'lastdigit' + + def as_sql(self, compiler, connection): + lhs, lhs_params = compiler.compile(self.lhs) + return 'SUBSTR(CAST(%s AS CHAR(2)), 2, 1)' % lhs, lhs_params + + class UpperBilateralTransform(models.Transform): bilateral = True lookup_name = 'upper' @@ -379,6 +387,15 @@ class BilateralTransformTests(TestCase): self.assertSequenceEqual(baseqs.filter(age__mult3__div3=42), [a1, a2, a3, a4]) self.assertSequenceEqual(baseqs.filter(age__div3__mult3=42), [a3]) + def test_transform_order_by(self): + with register_lookup(models.IntegerField, LastDigitTransform): + a1 = Author.objects.create(name='a1', age=11) + a2 = Author.objects.create(name='a2', age=23) + a3 = Author.objects.create(name='a3', age=32) + a4 = Author.objects.create(name='a4', age=40) + qs = Author.objects.order_by('age__lastdigit') + self.assertSequenceEqual(qs, [a4, a1, a3, a2]) + def test_bilateral_fexpr(self): with register_lookup(models.IntegerField, Mult3BilateralTransform): a1 = Author.objects.create(name='a1', age=1, average_rating=3.2) |
