#33935: Support unaccent function in JSONField values
-------------------------------------+-------------------------------------
Reporter: Foucauld Degeorges | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: QuerySet.extra | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Foucauld Degeorges:
Old description:
> 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.
>
> 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}}}.
New description:
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}}}.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/33935#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070182ac42f035-7d7aadc2-6bcb-4bbf-94de-af17e7e1c912-000000%40eu-central-1.amazonses.com.