A
A
Alexander Kulaga2018-08-07 21:24:20
Django
Alexander Kulaga, 2018-08-07 21:24:20

How to make case insensitive search in django db?

The title parameter comes in the url. It is necessary to make selection from a DB on this value. The following code only works with Latin characters.

def api_find_title(request, find_title=''):
    found = Post.objects.values('id', 'title', 'mark', 'phone_number', 'email')\
        .annotate(title_lower=Lower('title'))\
        .filter(title_lower=find_title.lower())

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vadim Shatalov, 2018-08-07
@AlexKulaga

https://docs.djangoproject.com/en/dev/ref/models/q...

R
Ranc58, 2018-08-07
@Ranc58

Try iexact

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question