0

I tried :

objects_list = Feed.objects.filter(
            job__istartswith__in=['AW', "cons", "S1"])

it shows me following error:

FieldError: Unsupported lookup 'istartwith' for CharField or join on the field not permitted.

if i tried like below, its working:

 objects_list = Feed.objects.filter(
                job__istartswith='AW')

what should I do for searching words startswith for the list of words in query?

Sekar Raj
  • 113
  • 1
  • 1
  • 11

1 Answers1

1

Django ORM does not support istartswith__in, I guess this is because database systems don't support that operation explicitly either.

You should use OR over several clauses in order to achieve this:

from django.db.models import Q
objects_list = Feed.objects.filter(
    Q(job__istartswith='AW') | 
    Q(job__istartswith='cons') |
    Q(job__istartswith='S1'))
jjmontes
  • 24,679
  • 4
  • 39
  • 51
  • that list contains many objects not only 3 values, it may be 20 also – Sekar Raj May 29 '17 at 13:54
  • 1
    You can build the query dynamically too. Check https://stackoverflow.com/questions/852414/how-to-dynamically-compose-an-or-query-filter-in-django . – jjmontes May 29 '17 at 13:55