In my database I have objects with slavic letters (śćę etc.). It is displayed correctly in my database, admin panel and even when I call my object in template. User can search for this object by providing what he wants in text input box: template.html
<input type="text" class="form-control" placeholder="Model" name="searched_model" id="searched_model" value="">
Hovewer when I filter the objects database in my view: views.py
found_products = ProductBase.objects.filter(Q(model__contains=searched_model).order_by('model')
It filters and displays correctly until slavic letter is provided.
For example, user wants object with model property as: ObjectŚĆobject
If he writes in my search field object
it will find and display ObjectŚĆobject
.
But if he writes objectŚ
or even Ś
only it will not show anything.
My view returns found_products
to template and displays it in table: template.html
{% for item in found_products %}
...
<td>
{{item.model}}
</td>
I don't know where lies the problem. In settings.py
I have correct LANGUAGE_CODE = 'pl-pl'
.
EDIT:
I did some logging and when I display searched phrase it shows correct string.
When I log the queryset after filter
it shows empty queryset. So the problem definitely lies in filtering data.
EDIT2:
When using other logging method I can see the SELECT
query as below when searching for nieokreś
:
(0.000) SELECT "zam_produktbase"."id", "zam_produktbase"."ean", "zam_produktbase"."model", "zam_produktbase"."kolor", "zam_produktbase"."symbol", "zam_produktbase"."aktywny", "zam_produktbase"."zam_id" FROM "zam_produktbase" WHERE ("za
m_produktbase"."model" LIKE '%nieokreś%' ESCAPE '\' AND "zam_produktbase"."symbol" LIKE '%%' ESCAPE '\' AND "zam_produktbase"."kolor" LIKE '%%' ESCAPE '\') ORDER BY "zam_produktbase"."model" ASC; args=('%nieokreś%', '%%', '%%')
EDIT3: Looks like the problem is in my sqlite database. When doing SELECT query it doesn't find non english letters.
EDIT4: It was a problem with capital letters, different filtering fixed the problem.