Opened 2 years ago

Last modified 2 years ago

#33935 closed Uncategorized

Support unaccent function in JSONField values — at Version 1

Reported by: Foucauld Degeorges Owned by: nobody
Component: Database layer (models, ORM) Version: 3.2
Severity: Normal Keywords: QuerySet.extra
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Foucauld Degeorges)

With a JSONField value with the following shape: my_object.my_json_field = {"en": "sôme téxt"}

Doing the following queryset: MyModel.objects.filter(my_json_field__en__unaccent__icontains="text") does not match the above record, because Django interprets "unaccent"' as a key to find in the JSON dict, whereas I meant the PostgreSQL unaccent function.

By comparison, with a CharField, MyModel.objects.filter(my_char_field__unaccent__icontains="test") works as expected.

It seems that unaccent is only supported on CharField and TextField for now, but since what I am trying to do is possible in SQL, it might be made possible as well using the ORM.

Details in this StackOverflow question: https://stackoverflow.com/questions/73385812/looking-up-value-in-jsonfield-with-unaccent-and-icontains
.

I am tagging QuerySet.extra because my workaround was to write the SQL where clause I expected using QuerySet.extra.

Change History (1)

comment:1 by Foucauld Degeorges, 2 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top