L
L
Lolo Penguin2021-02-18 19:44:13
Django
Lolo Penguin, 2021-02-18 19:44:13

How to implement a substring search in a string from a model case-insensitive in sqlite in Cyrillic?

I have a model with a CharField field:

class catalogModel(models.Model):
    title = models.CharField('Name', max_length = 100, null = True)

and I need to search through the catalogModel models using the title field, case insensitive
# поисковой запрос
search = request.GET['search']
catalogModel.objects.filter(title__icontains = search)


The only problem is that "__icontains" does not work correctly in "sqlite" with Cyrillic characters (it is case-sensitive, though it shouldn't be).
I was thinking of filtering by title by capitalizing it and the search term, like:
# поисковой запрос
search = request.GET['search']
catalogModel.objects.filter(title__ВЕРХНИЙ_РЕГИСТР__icontains = search.upper())

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alfss, 2021-02-19
@alfss

Make an additional field. In it, everything should be reduced to lower case and search for it.
You can also create title as COLLATE NOCASE

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question