[Django]-Wildcard searching in Django

6👍

Try using a less strict filter, like __contains:

elif val2=='Name':
        newData = EmployeeDetails.objects.filter(userName__contains=val3)
        flag=True 

Docs: http://docs.djangoproject.com/en/dev/ref/models/querysets/#contains

7👍

You can use contains query e.g.

Entry.objects.get(headline__contains='Lennon')

See http://docs.djangoproject.com/en/dev/ref/models/querysets/#contains

There are other options too like startswith, endswith, and you can do even regex search on most databases.

1👍

Probably field lookups will help you here. It lets to filter by beginning of the word, containing word and so on.

Leave a comment