ralphje / django-internationalflavor

Complementing django-localflavor with fields that are applicable to multiple countries
Other
25 stars 19 forks source link

Not sorted countries #13

Closed eriktelepovsky closed 6 years ago

eriktelepovsky commented 6 years ago

Hi. The choices of CountryFormField are not sorted. Is it a purpose?

Right now, I have to use choices argument to fix that like this:

choices = sorted(get_countries_lazy(), key=lambda o: o[1])

It would be great if the choices are sorted by country name by default.

ralphje commented 6 years ago

It should be, through the SortedSelect widget. It lazily sorts, so it works properly with different translations. Is your form using that widget?

eriktelepovsky commented 6 years ago

Yes, I already tried to use:

widget=SortedSelect()

and it worked for a while. Then I updated to Django 1.11.7 and it stopped working. Also, default model fields in the admin do not have sorted country choices:

image

ralphje commented 6 years ago

That's a shame. I'll look into it.

ralphje commented 6 years ago

I checked and it should work since commit:9677b8053b090ab5eb91fce31e9eaa8ba880c815. That commit hasn't made it into a release yet. Could you verify the current master fixes the issue?

eriktelepovsky commented 6 years ago

Yes, I confirm. Works fine in the current master ;) Thank you.

eriktelepovsky commented 3 years ago

I would like to reopen this issue:

country = forms.ChoiceField(label=_('Country'), choices=[('', _('Choose a country'))] + list(get_countries_lazy()))

it is sorted by keys, not values:

image