[Django]-Django ORM to find if a string contains column value

3👍

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.

1👍

You can use Q objects.

XYZ.objects.filter(Q(('{}__contains'.format("ABCDEFG"), "column1")))

Leave a comment