New function to sort words with accents.

171 views
Skip to first unread message

Paulo Maciel

unread,
May 5, 2015, 8:52:34 PM5/5/15
to django-d...@googlegroups.com
I am returning the query Something.objects.all().order_by(Lower('name'))  but the order is not respecting names that start with accent, causing these results appear at the end of ordering. We need a function to ignore accents and order correctly names with accents, as well as function Lower treats the results.

Currently:

arroz
baleia
dado
limão
xerox
água
ótimo

As it should be:

água
arroz
baleia
dado
limão
ótimo
xerox


We need a function like it to fix the problem:
Person.objects.all().order_by(Unaccent('name'))

This is a priority issue because it affects thousands of Brazilians and other nationalities who use Portuguese.


Stephen J. Butler

unread,
May 5, 2015, 9:06:03 PM5/5/15
to django-d...@googlegroups.com
This is part of the database collation, and as I understand the Django
docs it's not something Django handles internally. It's something you
set/tweak inside your database.

What database are you using? On MySQL the docs say to set a column
collation. On Oracle I believe you can change the NLS_SORT init
parameter.
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-develop...@googlegroups.com.
> To post to this group, send email to django-d...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-developers.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/27620089-a89e-4e13-9576-637e37395754%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Michael Manfre

unread,
May 5, 2015, 9:08:25 PM5/5/15
to django-d...@googlegroups.com
Hi Paulo,

Your issue can be solved by modifying the database collation or with application code (E.g. SlugField). The django-developer mailing is for discussion of the Django framework. The django-users mailing list is the appropriate place to start/continue a discussion about how you can resolve this issue.

Regards,
Michael Manfre

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/27620089-a89e-4e13-9576-637e37395754%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
GPG Fingerprint: 74DE D158 BAD0 EDF8

Aymeric Augustin

unread,
May 6, 2015, 1:52:20 AM5/6/15
to django-d...@googlegroups.com
If you're using PosgreSQL, django.contrib.postgres provides such a function.

-- 
Aymeric.

Anssi Kääriäinen

unread,
May 6, 2015, 5:48:38 AM5/6/15
to django-d...@googlegroups.com
There is a ticket for collations support. See
https://code.djangoproject.com/ticket/21181. I think a Collate
expression would be very welcome addition.
> https://groups.google.com/d/msgid/django-developers/F4794B20-EA76-4A41-A4CD-8D2DA473E82F%40polytechnique.org.
Reply all
Reply to author
Forward
0 new messages