#33935 closed Uncategorized (duplicate)

Support unaccent function in JSONField values

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 (2)

comment:1 by Foucauld Degeorges, 21 months ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 21 months ago

Resolution: duplicate
Status: newclosed

Duplicate of #26511 (see also #27824 and Simon's comment).

Note: See TracTickets for help on using tickets.
Back to Top