(self)
| 39 | Author.objects.annotate(raises=Substr("name", 0)) |
| 40 | |
| 41 | def test_expressions(self): |
| 42 | Author.objects.create(name="John Smith", alias="smithj") |
| 43 | Author.objects.create(name="Rhonda") |
| 44 | substr = Substr(Upper("name"), StrIndex("name", V("h")), 5) |
| 45 | authors = Author.objects.annotate(name_part=substr) |
| 46 | self.assertQuerySetEqual( |
| 47 | authors.order_by("name"), ["HN SM", "HONDA"], lambda a: a.name_part |
| 48 | ) |