Django国家按翻译名称排序 [英] Django countries order by translated name

查看:145
本文介绍了Django国家按翻译名称排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用django_countries并在我的一个模型中添加了一个字段

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

推荐答案

这是解决方案,基于这个

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

这篇关于Django国家按翻译名称排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆