Re: Django ORM queryset substring on a column

2019-01-04 Thread Todor Velichkov
You said you cannot use `endswith` because `-A111` and `-111` will match, well what about just use endswith='-111' ? On Thursday, January 3, 2019 at 3:17:43 PM UTC+2, BIJAL MANIAR wrote: > > > Hello, > > Consider below column in mysql table Employee. I need to write django orm > query for below

Re: Django ORM queryset substring on a column

2019-01-04 Thread Simon Charette
You can use a Func expression for this purpose[0] Employee.objects.annotate( emp_number_suffix=Func('emp_number', Value('-'), -1, function='substring_index'), ).filter( emp_number_suffix='111', ).values('emp_number') Cheers, Simon [0] https://docs.djangoproject.com/en/2.1/ref/models/ex

Re: Django ORM queryset substring on a column

2019-01-04 Thread Krishnasagar Subhedarpage
You can try with __contains queryset. Regards, Krishnasagar Subhedarpage On Fri, 4 Jan 2019 at 15:34, BIJAL MANIAR wrote: > > Hello, > > Can anyone please help with this. > > Thanks, > Bijal > > On Thursday, January 3, 2019 at 6:47:43 PM UTC+5:30, BIJAL MANIAR wrote: >> >> >> Hello, >> >> Co

Re: Django ORM queryset substring on a column

2019-01-04 Thread BIJAL MANIAR
Hello, Can anyone please help with this. Thanks, Bijal On Thursday, January 3, 2019 at 6:47:43 PM UTC+5:30, BIJAL MANIAR wrote: > > > Hello, > > Consider below column in mysql table Employee. I need to write django orm > query for below mysql query. > emp_number > 4-DEF-A111 > 3-MNO-333 > 2-DE

Django ORM queryset substring on a column

2019-01-03 Thread BIJAL MANIAR
Hello, Consider below column in mysql table Employee. I need to write django orm query for below mysql query. emp_number 4-DEF-A111 3-MNO-333 2-DEF-222 1-ABC-111 Mysql query which splits by '-' and matches against last index. SELECT * from Employee WHERE substring_index(emp_number, '-', -1) =