Django国家/地区:翻译选项排序错误(但在管理中有效)

Django国家/地区:翻译选项排序错误(但在管理中有效),django,django-views,Django,Django Views,我像下面这样使用。在我看来,似乎是根据英语原始值对所选项目进行排序(例如,Deutschland将在g(=德国)下找到),但在管理中,值是根据当前语言排序的。这不是通过(我通过禁用JS来尝试的)。我不知道如何解决这个问题。版本:Django 1.5.5,Django Countries 2.1.2 models.py from django_countries.fields import CountryField class MyModel(ModelSubClass): country

我像下面这样使用。在我看来,似乎是根据英语原始值对所选项目进行排序(例如,
Deutschland
将在
g
(=德国)下找到),但在管理中,值是根据当前语言排序的。这不是通过(我通过禁用JS来尝试的)。我不知道如何解决这个问题。版本:Django 1.5.5,Django Countries 2.1.2

models.py

from django_countries.fields import CountryField
class MyModel(ModelSubClass):
    country = CountryField(_('country'), blank=True)
    #...

class MyForm(ModelSubForm):
    class Meta(object):
        model = MyModel
        #...

    def __init__(self, *args, **kwargs):
    super(MyForm, self).__init__(*args, **kwargs)
    self.fields['country'].required = True
    #...
views.py

class MyCreateView(CreateView):
    model = MyModel
    form_class = MyForm
    # overriding `dispatch`, `get_initial`, `form_valid`, `get_context_data`, `get_success_url`
my_template.html

{% extends "base.html" %}
{% load i18n %}
{% block content %}
<form class="form-horizontal" role="form" method="post" action="">
{% csrf_token %}
{{ form }}
<button type="submit" class="btn btn-success">{% trans 'Submit' %}</button>
</form>
{# ... #}
{% endblock content %}
{%extends“base.html”%}
{%load i18n%}
{%block content%}
{%csrf_令牌%}
{{form}}
{%trans'提交'%}
{# ... #}
{%endblock内容%}
如果需要,我可以提供更多信息


另一件事是,在管理中,使用非ASCII大写字母的国家的顺序是错误的。但我认为这是。

以前也有人问过类似的问题

答案是:

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

MyForm
中的
\uuuu init\uuuu
中的原始值覆盖选项:

from django_countries import countries
class MyForm(ModelSubForm):
    class Meta(object):
        model = MyModel
        #...

    def __init__(self, *args, **kwargs):
        super(MyForm, self).__init__(*args, **kwargs)
        self.fields['country'].choices = [self.fields['country'].choices[0]] + list(countries)
        #...
使用选项的第一项保留空值(
-----------

据我所知,问题在于models.py中字段的
选项
在服务器启动时加载,即加载一次。在表单中,您可以根据请求覆盖它。排序由
国家/地区
(同一文件中的
国家/地区
的实例)完成


我愿意找到更好的解决方案。

我以前读过这篇文章。我正在寻找非JS解决方案。或者是我遗漏了什么,并且在管理中也按JS排序?