djangodjango-modelsdjango-countries

Django countries order by translated name


I started using django_countries and added a field to one of my models

country = CountryField(blank=True)

The problem is the users language is spanish and when the form shows the list of countries they are correctly translated, but they ordered by the code I guess, or by the English name.

I want it to be ordered by the display name so the users can easily search any country by typing the first letter and then going down until the find it (the way most of people does).

Any ideas? Thank uou for your time


Solution

  • This was the solution, based on this

    function sort(a, b) {               
            return (a.innerHTML > b.innerHTML) ? 1 : -1;
        };
    $('#select_id option').sort(sort).appendTo('#select_id');