1

I am trying to slice the last two characters of a field and annotate it to query result, using the method given in this post. Something like:

Person.objects.all()\
.annotate(
    code = Substr('Number', 1, -2),
)

The above code returns an empty string as soon as I use negative values as the third argument. How can I achieve this?

Azee
  • 329
  • 6
  • 20
  • 1
    Since the question asks for the last two character (as we use negative index for python arrays), this is not a duplicate question at all. @schwobaseggl – Happy Ahmad Jan 03 '18 at 07:50
  • The answer could be found [here](https://stackoverflow.com/questions/48017719/concatenation-of-a-field-related-to-multiple-rows-of-a-record-in-query-set-in-dj). – Azee Jan 14 '18 at 10:29

0 Answers0