I'd like to know how to write ORM code of the following SQL:
select * from t1 where 'ABCDEFG' LIKE CONCAT('%',column1,'%');
It seems that Django supports only the following code:
XYZ.objects.filter(column1__contains='ABCDEFG')
What I want is something like that:
XYZ.objects.filter('ABCDEFG'__contains=column1)
I'd like to know the correct way of Python/Django.
Thank you.
XYZ.objects\
.annotate(querystring=Value('ABCDEFG', output_field=CharField()))\
.filter(querystring__icontains=F('column1'))
My team mate found this one. It works for me. Under the hood it gives the same SQL as topic starter mentioned above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With